annotate light9/showconfig.py @ 943:3aae87f6777a

vidref grab images for snapshots even if a song is not playing Ignore-this: 81b9b8c86a6326be3dd5a7d900f16a1b
author drewp@bigasterisk.com
date Thu, 13 Jun 2013 01:44:05 +0000
parents f6c73fafffe9
children 08814a44ae4e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
832
231a8b3aedc3 showconfig still reads n3 files on its own for legacy code. reads anything in top dir, not just config.n3 and patch.n3
Drew Perttula <drewp@bigasterisk.com>
parents: 717
diff changeset
1 import time, logging, warnings
231a8b3aedc3 showconfig still reads n3 files on its own for legacy code. reads anything in top dir, not just config.n3 and patch.n3
Drew Perttula <drewp@bigasterisk.com>
parents: 717
diff changeset
2 from twisted.python.filepath import FilePath
356
c6aabf5bd3bc big KC speedup from not reloading config.n3 constantly
Drew Perttula <drewp@bigasterisk.com>
parents: 334
diff changeset
3 from os import path, getenv
686
a301a0039c66 buildout and rdflib updates
Drew Perttula <drewp@bigasterisk.com>
parents: 653
diff changeset
4 from rdflib import Graph
304
5f9cf6174e62 ascoltami now uses rdf for config
Drew Perttula <drewp@bigasterisk.com>
parents: 227
diff changeset
5 from rdflib import URIRef
5f9cf6174e62 ascoltami now uses rdf for config
Drew Perttula <drewp@bigasterisk.com>
parents: 227
diff changeset
6 from namespaces import MUS, L9
537
1929e0e1053e showconfig logs about what n3 files it's reading
drewp@bigasterisk.com
parents: 532
diff changeset
7 log = logging.getLogger('showconfig')
304
5f9cf6174e62 ascoltami now uses rdf for config
Drew Perttula <drewp@bigasterisk.com>
parents: 227
diff changeset
8
832
231a8b3aedc3 showconfig still reads n3 files on its own for legacy code. reads anything in top dir, not just config.n3 and patch.n3
Drew Perttula <drewp@bigasterisk.com>
parents: 717
diff changeset
9 _config = None # graph
304
5f9cf6174e62 ascoltami now uses rdf for config
Drew Perttula <drewp@bigasterisk.com>
parents: 227
diff changeset
10 def getGraph():
832
231a8b3aedc3 showconfig still reads n3 files on its own for legacy code. reads anything in top dir, not just config.n3 and patch.n3
Drew Perttula <drewp@bigasterisk.com>
parents: 717
diff changeset
11 warnings.warn("code that's using showconfig.getGraph should be "
231a8b3aedc3 showconfig still reads n3 files on its own for legacy code. reads anything in top dir, not just config.n3 and patch.n3
Drew Perttula <drewp@bigasterisk.com>
parents: 717
diff changeset
12 "converted to use the sync graph", stacklevel=2)
356
c6aabf5bd3bc big KC speedup from not reloading config.n3 constantly
Drew Perttula <drewp@bigasterisk.com>
parents: 334
diff changeset
13 global _config
832
231a8b3aedc3 showconfig still reads n3 files on its own for legacy code. reads anything in top dir, not just config.n3 and patch.n3
Drew Perttula <drewp@bigasterisk.com>
parents: 717
diff changeset
14 if _config is None:
231a8b3aedc3 showconfig still reads n3 files on its own for legacy code. reads anything in top dir, not just config.n3 and patch.n3
Drew Perttula <drewp@bigasterisk.com>
parents: 717
diff changeset
15 graph = Graph()
871
f6c73fafffe9 legacy config readers also peek in the show's build/ dir
Drew Perttula <drewp@bigasterisk.com>
parents: 832
diff changeset
16 for f in FilePath(root()).globChildren("*.n3") + FilePath(root()).globChildren("build/*.n3"):
832
231a8b3aedc3 showconfig still reads n3 files on its own for legacy code. reads anything in top dir, not just config.n3 and patch.n3
Drew Perttula <drewp@bigasterisk.com>
parents: 717
diff changeset
17 log.info("reading %s", f)
231a8b3aedc3 showconfig still reads n3 files on its own for legacy code. reads anything in top dir, not just config.n3 and patch.n3
Drew Perttula <drewp@bigasterisk.com>
parents: 717
diff changeset
18 graph.parse(location=f.path, format='n3')
231a8b3aedc3 showconfig still reads n3 files on its own for legacy code. reads anything in top dir, not just config.n3 and patch.n3
Drew Perttula <drewp@bigasterisk.com>
parents: 717
diff changeset
19 _config = graph
231a8b3aedc3 showconfig still reads n3 files on its own for legacy code. reads anything in top dir, not just config.n3 and patch.n3
Drew Perttula <drewp@bigasterisk.com>
parents: 717
diff changeset
20 return _config
219
21b458127924 adding showconfig.py, which should have been added a while ago
drewp@bigasterisk.com
parents:
diff changeset
21
21b458127924 adding showconfig.py, which should have been added a while ago
drewp@bigasterisk.com
parents:
diff changeset
22 def root():
21b458127924 adding showconfig.py, which should have been added a while ago
drewp@bigasterisk.com
parents:
diff changeset
23 r = getenv("LIGHT9_SHOW")
21b458127924 adding showconfig.py, which should have been added a while ago
drewp@bigasterisk.com
parents:
diff changeset
24 if r is None:
220
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents: 219
diff changeset
25 raise OSError(
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents: 219
diff changeset
26 "LIGHT9_SHOW env variable has not been set to the show root")
219
21b458127924 adding showconfig.py, which should have been added a while ago
drewp@bigasterisk.com
parents:
diff changeset
27 return r
21b458127924 adding showconfig.py, which should have been added a while ago
drewp@bigasterisk.com
parents:
diff changeset
28
617
94039df5cdd9 create Playlist class which is now used in wavecurve, musicPad, and ascoltami2.
David McClosky <dmcc@bigasterisk.com>
parents: 537
diff changeset
29 def showUri():
94039df5cdd9 create Playlist class which is now used in wavecurve, musicPad, and ascoltami2.
David McClosky <dmcc@bigasterisk.com>
parents: 537
diff changeset
30 """Return the show URI associated with $LIGHT9_SHOW."""
619
bc0bd8ad8ba9 bug in showUri method, which has apparently never been used
drewp@bigasterisk.com
parents: 617
diff changeset
31 return URIRef(file(path.join(root(), 'URI')).read().strip())
617
94039df5cdd9 create Playlist class which is now used in wavecurve, musicPad, and ascoltami2.
David McClosky <dmcc@bigasterisk.com>
parents: 537
diff changeset
32
420
d4284e68e51c better search for mpd config file (look in /etc/mpd.conf)
drewp@bigasterisk.com
parents: 366
diff changeset
33 def findMpdHome():
d4284e68e51c better search for mpd config file (look in /etc/mpd.conf)
drewp@bigasterisk.com
parents: 366
diff changeset
34 """top of the music directory for the mpd on this system,
d4284e68e51c better search for mpd config file (look in /etc/mpd.conf)
drewp@bigasterisk.com
parents: 366
diff changeset
35 including trailing slash"""
d4284e68e51c better search for mpd config file (look in /etc/mpd.conf)
drewp@bigasterisk.com
parents: 366
diff changeset
36
d4284e68e51c better search for mpd config file (look in /etc/mpd.conf)
drewp@bigasterisk.com
parents: 366
diff changeset
37 mpdHome = None
526
a60a73463ef0 vidref now pretty much saves and loads frames
drewp@bigasterisk.com
parents: 423
diff changeset
38 for mpdConfFilename in ["/my/dl/modified/mpd/src/mpdconf-testing",
a60a73463ef0 vidref now pretty much saves and loads frames
drewp@bigasterisk.com
parents: 423
diff changeset
39 "~/.mpdconf", "/etc/mpd.conf"]:
420
d4284e68e51c better search for mpd config file (look in /etc/mpd.conf)
drewp@bigasterisk.com
parents: 366
diff changeset
40 try:
d4284e68e51c better search for mpd config file (look in /etc/mpd.conf)
drewp@bigasterisk.com
parents: 366
diff changeset
41 mpdConfFile = open(path.expanduser(mpdConfFilename))
d4284e68e51c better search for mpd config file (look in /etc/mpd.conf)
drewp@bigasterisk.com
parents: 366
diff changeset
42 except IOError:
d4284e68e51c better search for mpd config file (look in /etc/mpd.conf)
drewp@bigasterisk.com
parents: 366
diff changeset
43 continue
d4284e68e51c better search for mpd config file (look in /etc/mpd.conf)
drewp@bigasterisk.com
parents: 366
diff changeset
44 for line in mpdConfFile:
d4284e68e51c better search for mpd config file (look in /etc/mpd.conf)
drewp@bigasterisk.com
parents: 366
diff changeset
45 if line.startswith("music_directory"):
d4284e68e51c better search for mpd config file (look in /etc/mpd.conf)
drewp@bigasterisk.com
parents: 366
diff changeset
46 mpdHome = line.split()[1].strip('"')
d4284e68e51c better search for mpd config file (look in /etc/mpd.conf)
drewp@bigasterisk.com
parents: 366
diff changeset
47 return mpdHome.rstrip(path.sep) + path.sep
d4284e68e51c better search for mpd config file (look in /etc/mpd.conf)
drewp@bigasterisk.com
parents: 366
diff changeset
48
d4284e68e51c better search for mpd config file (look in /etc/mpd.conf)
drewp@bigasterisk.com
parents: 366
diff changeset
49 raise ValueError("can't find music_directory in any mpd config file")
d4284e68e51c better search for mpd config file (look in /etc/mpd.conf)
drewp@bigasterisk.com
parents: 366
diff changeset
50
318
fcf9755d9a75 patch showconfig again
drewp@bigasterisk.com
parents: 317
diff changeset
51 def songOnDisk(song):
423
2b2f5da47c5d config file now lists paths in the same form you'd give to mpd. New cmdline on ascoltami to specify the song list from config.n3
drewp@bigasterisk.com
parents: 420
diff changeset
52 """given a song URI, where's the on-disk file that mpd would read?"""
318
fcf9755d9a75 patch showconfig again
drewp@bigasterisk.com
parents: 317
diff changeset
53 graph = getGraph()
644
98ec0fbbe980 switch song config to factor out the music dir
Drew Perttula <drewp@bigasterisk.com>
parents: 638
diff changeset
54 root = graph.value(showUri(), L9['musicRoot'])
98ec0fbbe980 switch song config to factor out the music dir
Drew Perttula <drewp@bigasterisk.com>
parents: 638
diff changeset
55 if not root:
98ec0fbbe980 switch song config to factor out the music dir
Drew Perttula <drewp@bigasterisk.com>
parents: 638
diff changeset
56 raise ValueError("%s has no :musicRoot" % showUri())
98ec0fbbe980 switch song config to factor out the music dir
Drew Perttula <drewp@bigasterisk.com>
parents: 638
diff changeset
57
98ec0fbbe980 switch song config to factor out the music dir
Drew Perttula <drewp@bigasterisk.com>
parents: 638
diff changeset
58 name = graph.value(song, L9['songFilename'])
98ec0fbbe980 switch song config to factor out the music dir
Drew Perttula <drewp@bigasterisk.com>
parents: 638
diff changeset
59 if not name:
98ec0fbbe980 switch song config to factor out the music dir
Drew Perttula <drewp@bigasterisk.com>
parents: 638
diff changeset
60 raise ValueError("Song %r has no :songFilename" % song)
98ec0fbbe980 switch song config to factor out the music dir
Drew Perttula <drewp@bigasterisk.com>
parents: 638
diff changeset
61
717
d8202a0a7fd5 fix up musicpad and wavecurve. ascoltami2 can now use relative paths in the config
Drew Perttula <drewp@bigasterisk.com>
parents: 686
diff changeset
62 return path.abspath(path.join(root, name))
220
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents: 219
diff changeset
63
357
7771f37252da curvecalc persistence, wavecurve -a option
Drew Perttula <drewp@bigasterisk.com>
parents: 356
diff changeset
64 def songFilenameFromURI(uri):
7771f37252da curvecalc persistence, wavecurve -a option
Drew Perttula <drewp@bigasterisk.com>
parents: 356
diff changeset
65 """
7771f37252da curvecalc persistence, wavecurve -a option
Drew Perttula <drewp@bigasterisk.com>
parents: 356
diff changeset
66 'http://light9.bigasterisk.com/show/dance2007/song8' -> 'song8'
7771f37252da curvecalc persistence, wavecurve -a option
Drew Perttula <drewp@bigasterisk.com>
parents: 356
diff changeset
67
7771f37252da curvecalc persistence, wavecurve -a option
Drew Perttula <drewp@bigasterisk.com>
parents: 356
diff changeset
68 everything that uses this should be deprecated for real URIs
7771f37252da curvecalc persistence, wavecurve -a option
Drew Perttula <drewp@bigasterisk.com>
parents: 356
diff changeset
69 everywhere"""
7771f37252da curvecalc persistence, wavecurve -a option
Drew Perttula <drewp@bigasterisk.com>
parents: 356
diff changeset
70 assert isinstance(uri, URIRef)
7771f37252da curvecalc persistence, wavecurve -a option
Drew Perttula <drewp@bigasterisk.com>
parents: 356
diff changeset
71 return uri.split('/')[-1]
7771f37252da curvecalc persistence, wavecurve -a option
Drew Perttula <drewp@bigasterisk.com>
parents: 356
diff changeset
72
617
94039df5cdd9 create Playlist class which is now used in wavecurve, musicPad, and ascoltami2.
David McClosky <dmcc@bigasterisk.com>
parents: 537
diff changeset
73 def getSongsFromShow(graph, show):
94039df5cdd9 create Playlist class which is now used in wavecurve, musicPad, and ascoltami2.
David McClosky <dmcc@bigasterisk.com>
parents: 537
diff changeset
74 playList = graph.value(show, L9['playList'])
94039df5cdd9 create Playlist class which is now used in wavecurve, musicPad, and ascoltami2.
David McClosky <dmcc@bigasterisk.com>
parents: 537
diff changeset
75 if not playList:
94039df5cdd9 create Playlist class which is now used in wavecurve, musicPad, and ascoltami2.
David McClosky <dmcc@bigasterisk.com>
parents: 537
diff changeset
76 raise ValueError("%r has no l9:playList" % show)
94039df5cdd9 create Playlist class which is now used in wavecurve, musicPad, and ascoltami2.
David McClosky <dmcc@bigasterisk.com>
parents: 537
diff changeset
77 songs = list(graph.items(playList))
94039df5cdd9 create Playlist class which is now used in wavecurve, musicPad, and ascoltami2.
David McClosky <dmcc@bigasterisk.com>
parents: 537
diff changeset
78
94039df5cdd9 create Playlist class which is now used in wavecurve, musicPad, and ascoltami2.
David McClosky <dmcc@bigasterisk.com>
parents: 537
diff changeset
79 return songs
94039df5cdd9 create Playlist class which is now used in wavecurve, musicPad, and ascoltami2.
David McClosky <dmcc@bigasterisk.com>
parents: 537
diff changeset
80
219
21b458127924 adding showconfig.py, which should have been added a while ago
drewp@bigasterisk.com
parents:
diff changeset
81 def curvesDir():
21b458127924 adding showconfig.py, which should have been added a while ago
drewp@bigasterisk.com
parents:
diff changeset
82 return path.join(root(),"curves")
21b458127924 adding showconfig.py, which should have been added a while ago
drewp@bigasterisk.com
parents:
diff changeset
83
21b458127924 adding showconfig.py, which should have been added a while ago
drewp@bigasterisk.com
parents:
diff changeset
84 def songFilename(song):
357
7771f37252da curvecalc persistence, wavecurve -a option
Drew Perttula <drewp@bigasterisk.com>
parents: 356
diff changeset
85 return path.join(root(), "music", "%s.wav" % song)
219
21b458127924 adding showconfig.py, which should have been added a while ago
drewp@bigasterisk.com
parents:
diff changeset
86
21b458127924 adding showconfig.py, which should have been added a while ago
drewp@bigasterisk.com
parents:
diff changeset
87 def subtermsForSong(song):
21b458127924 adding showconfig.py, which should have been added a while ago
drewp@bigasterisk.com
parents:
diff changeset
88 return path.join(root(),"subterms",song)
21b458127924 adding showconfig.py, which should have been added a while ago
drewp@bigasterisk.com
parents:
diff changeset
89
21b458127924 adding showconfig.py, which should have been added a while ago
drewp@bigasterisk.com
parents:
diff changeset
90 def subFile(subname):
21b458127924 adding showconfig.py, which should have been added a while ago
drewp@bigasterisk.com
parents:
diff changeset
91 return path.join(root(),"subs",subname)
21b458127924 adding showconfig.py, which should have been added a while ago
drewp@bigasterisk.com
parents:
diff changeset
92
21b458127924 adding showconfig.py, which should have been added a while ago
drewp@bigasterisk.com
parents:
diff changeset
93 def subsDir():
21b458127924 adding showconfig.py, which should have been added a while ago
drewp@bigasterisk.com
parents:
diff changeset
94 return path.join(root(),'subs')
21b458127924 adding showconfig.py, which should have been added a while ago
drewp@bigasterisk.com
parents:
diff changeset
95
227
c7797ad42684 song pre/post mostly working
drewp@bigasterisk.com
parents: 220
diff changeset
96 def prePostSong():
304
5f9cf6174e62 ascoltami now uses rdf for config
Drew Perttula <drewp@bigasterisk.com>
parents: 227
diff changeset
97 graph = getGraph()
5f9cf6174e62 ascoltami now uses rdf for config
Drew Perttula <drewp@bigasterisk.com>
parents: 227
diff changeset
98 return [graph.value(MUS['preSong'], L9['showPath']),
5f9cf6174e62 ascoltami now uses rdf for config
Drew Perttula <drewp@bigasterisk.com>
parents: 227
diff changeset
99 graph.value(MUS['postSong'], L9['showPath'])]