changeset 308:3536b1e4dc8b

merge some rdf changes
author drewp@bigasterisk.com
date Tue, 20 Mar 2007 02:34:28 +0000
parents 686df28153a9
children a3dc9c1508ab
files bin/ascoltami light9/showconfig.py
diffstat 2 files changed, 29 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/bin/ascoltami	Fri Jun 16 16:54:09 2006 +0000
+++ b/bin/ascoltami	Tue Mar 20 02:34:28 2007 +0000
@@ -168,10 +168,11 @@
     
         self.autopausedthissong = False
         self.mpd.clear()
-        self.mpd.add(showconfig.songInMpd(self.pre_post_names[0]))
-        self.mpd.add(showconfig.songInMpd(song_path))
-        self.mpd.add(showconfig.songInMpd(self.pre_post_names[1]))
-        self.filename_var.set(song_path)
+        self.mpd.add(showconfig.songInMpd(MUS['preSong']))
+        self.mpd.add(showconfig.songInMpd(song))
+        self.mpd.add(showconfig.songInMpd(MUS['postSong']))
+        self.filename_var.set(graph.value(song, L9['showPath']))
+        self.song_uri = song
 
         self.set_total_time(song)
         self.mpd.seek(seconds=0, song=0)
--- a/light9/showconfig.py	Fri Jun 16 16:54:09 2006 +0000
+++ b/light9/showconfig.py	Tue Mar 20 02:34:28 2007 +0000
@@ -24,10 +24,30 @@
     /my/music. song is a file in musicDir; this function returns a
     version starting with the mpd path, but minus the mpd root itself.
     the mpc ~/.mpdconf """
-    
-    if 'dance2005' in root():
-        return "projects/dance2005/%s" % song
-    raise NotImplementedError
+
+    assert isinstance(song, URIRef), "songInMpd now takes URIRefs"
+
+    mpdHome = None
+    for line in open(path.expanduser("~/.mpdconf")):
+        if line.startswith("music_directory"):
+            mpdHome = line.split()[1].strip('"')
+    if mpdHome is None:
+        raise ValueError("can't find music_directory in your ~/.mpdconf")
+    mpdHome = mpdHome.rstrip(path.sep) + path.sep
+
+    songFullPath = songOnDisk(song)
+    if not songFullPath.startswith(mpdHome):
+        raise ValueError("the song path %r is not under your MPD music_directory (%r)" % (songFullPath, mpdHome))
+        
+    mpdRelativePath = songFullPath[len(mpdHome):]
+    if path.join(mpdHome, mpdRelativePath) != songFullPath:
+        raise ValueError("%r + %r doesn't make the songpath %r" % (mpdHome, mpdRelativePath, songFullPath))
+    return mpdRelativePath.encode('ascii')
+
+def songOnDisk(song):
+    graph = getGraph()
+    songFullPath = path.join(root(), graph.value(song, L9['showPath']))
+    return songFullPath
 
 def curvesDir():
     return path.join(root(),"curves")