changeset 420:d4284e68e51c

better search for mpd config file (look in /etc/mpd.conf)
author drewp@bigasterisk.com
date Mon, 09 Jun 2008 00:54:47 +0000
parents 632539a8c30e
children 6f62aea409cb
files light9/showconfig.py
diffstat 1 files changed, 21 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/light9/showconfig.py	Mon Jun 09 00:54:24 2008 +0000
+++ b/light9/showconfig.py	Mon Jun 09 00:54:47 2008 +0000
@@ -36,6 +36,25 @@
             "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
@@ -48,14 +67,8 @@
 
     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))