Files
@ 42eae412571a
Branch filter:
Location: light9/light9/showconfig.py
42eae412571a
4.0 KiB
text/x-python
new readme for 2011
Ignore-this: 375387160df1bcb2963b21b9096d03d4
Ignore-this: 375387160df1bcb2963b21b9096d03d4
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 | import time, logging
from os import path, getenv
from rdflib.Graph import Graph
from rdflib import URIRef
from namespaces import MUS, L9
log = logging.getLogger('showconfig')
_config = (None, None, None) # graph, mtime, len
def getGraph():
global _config
configPath = path.join(root(), 'config.n3')
# file patch.n3 mtime is not currently being checked
now = time.time()
diskMtime = path.getmtime(configPath)
if diskMtime <= _config[1]:
log.info("config.n3 hasn't changed")
graph = _config[0]
# i'm scared of some program modifying the graph, and then i
# return that from a new getGraph call. Maybe I should be
# copying it right here, or doing something clever with
# contexts
assert len(graph) == _config[2]
return _config[0]
graph = Graph()
log.info("reading %s", configPath)
graph.parse(configPath, format='n3')
patchPath = path.join(root(), "patch.n3")
log.info("reading %s", patchPath)
graph.parse(patchPath, 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 showUri():
"""Return the show URI associated with $LIGHT9_SHOW."""
return URIRef(file(path.join(root(), 'URI')).read().strip())
def findMpdHome():
"""top of the music directory for the mpd on this system,
including trailing slash"""
mpdHome = None
for mpdConfFilename in ["/my/dl/modified/mpd/src/mpdconf-testing",
"~/.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):
"""
get the mpd path (with correct encoding) from the song URI
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"
mpdPath = getGraph().value(song, L9['showPath'])
if mpdPath is None:
raise ValueError("no mpd path found for subject=%r" % song)
return mpdPath.encode('ascii')
def songOnDisk(song):
"""given a song URI, where's the on-disk file that mpd would read?"""
graph = getGraph()
showPath = graph.value(song, L9['showPath'])
if not showPath:
raise ValueError("no mpd path found for subject=%r" % song)
if showPath.startswith("file://"):
showPath = showPath[7:]
return showPath
def songFilenameFromURI(uri):
"""
'http://light9.bigasterisk.com/show/dance2007/song8' -> 'song8'
everything that uses this should be deprecated for real URIs
everywhere"""
assert isinstance(uri, URIRef)
return uri.split('/')[-1]
def getSongsFromShow(graph, show):
playList = graph.value(show, L9['playList'])
if not playList:
raise ValueError("%r has no l9:playList" % show)
songs = list(graph.items(playList))
return songs
def curvesDir():
return path.join(root(),"curves")
def songFilename(song):
return path.join(root(), "music", "%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 prePostSong():
graph = getGraph()
return [graph.value(MUS['preSong'], L9['showPath']),
graph.value(MUS['postSong'], L9['showPath'])]
|