Changeset - d4284e68e51c
[Not reviewed]
default
0 1 0
drewp@bigasterisk.com - 17 years ago 2008-06-09 00:54:47
drewp@bigasterisk.com
better search for mpd config file (look in /etc/mpd.conf)
1 file changed with 20 insertions and 7 deletions:
0 comments (0 inline, 0 general)
light9/showconfig.py
Show inline comments
 
@@ -27,43 +27,56 @@ def getGraph():
 
    graph.parse(path.join(root(), "patch.n3"), format="n3")
 
    
 
    _config = (graph, diskMtime, len(graph))
 
    return graph
 

	
 
def root():
 
    r = getenv("LIGHT9_SHOW")
 
    if r is None:
 
        raise OSError(
 
            "LIGHT9_SHOW env variable has not been set to the show root")
 
    return r
 

	
 
def findMpdHome():
 
    """top of the music directory for the mpd on this system,
 
    including trailing slash"""
 
    
 
    mpdHome = None
 
    for mpdConfFilename in ["~/.mpdconf", "/etc/mpd.conf"]:
 
        try:
 
            mpdConfFile = open(path.expanduser(mpdConfFilename))
 
        except IOError:
 
            continue
 
        for line in mpdConfFile:
 
            if line.startswith("music_directory"):
 
                mpdHome = line.split()[1].strip('"')
 
                return mpdHome.rstrip(path.sep) + path.sep  
 

	
 
    raise ValueError("can't find music_directory in any mpd config file")
 

	
 

	
 

	
 
def songInMpd(song):
 

	
 
    """mpd only works off its own musicroot, which for me is
 
    /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
 

	
 
    changed root to /home/drewp/projects/light9/show/dance2005 for now
 
    """
 

	
 
    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
 
    mpdHome = findMpdHome()
 

	
 
    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()
0 comments (0 inline, 0 general)