view light9/showconfig.py @ 312:d5c81bb7d822

mpd_timing_test edit
author Drew Perttula <drewp@bigasterisk.com>
date Fri, 16 Jun 2006 16:59:51 +0000
parents 3536b1e4dc8b
children ec44c6ddc8cf
line wrap: on
line source

from os import path,getenv
from rdflib.Graph import Graph
from rdflib import URIRef
from namespaces import MUS, L9

def getGraph():
    graph = Graph()
    graph.parse(path.join(root(), 'config.n3'), format='n3')
    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 musicDir():
    return path.join(root(),"music")

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 """

    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")

def songFilename(song):
    return path.join(musicDir(),"%s.wav" % song)

def subtermsForSong(song):
    return path.join(root(),"subterms",song)

def subFile(subname):
    return path.join(root(),"subs",subname)

def subsDir():
    return path.join(root(),'subs')

def patchData():
    return path.join(root(),"patchdata.py")

def prePostSong():
    graph = getGraph()
    return [graph.value(MUS['preSong'], L9['showPath']),
            graph.value(MUS['postSong'], L9['showPath'])]