# HG changeset patch # User drewp@bigasterisk.com # Date 2007-03-20 02:35:22 # Node ID 9e4cd9704511bde410e023603a2f965caa666afb # Parent ec44c6ddc8cfe4e5abc8b457d2e734ac6aeece6d merge showconfig again diff --git a/light9/showconfig.py b/light9/showconfig.py --- a/light9/showconfig.py +++ b/light9/showconfig.py @@ -27,10 +27,30 @@ def songInMpd(song): changed root to /home/drewp/projects/light9/show/dance2005 for now """ - - 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")