annotate light9/Patch.py @ 826:05aabe3d7b02

fix some minor issues with graph contexts Ignore-this: 7fd366a4b6cbd94af6f9edb1b4b4c6fc
author Drew Perttula <drewp@bigasterisk.com>
date Tue, 04 Jun 2013 20:28:49 +0000
parents 40b6a06bd090
children 71e9f35dd0e1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
211
9b360ee8636e move patchdata into show/, pull out curve.py from curvecalc, more networking.py unification
drewp@bigasterisk.com
parents: 210
diff changeset
1 import os
334
42e4c4728a66 ascoltami, subcomposer, keyboardcomposer use rdf show data; raise channel count to 270
drewp@bigasterisk.com
parents: 216
diff changeset
2 from rdflib import RDF
42e4c4728a66 ascoltami, subcomposer, keyboardcomposer use rdf show data; raise channel count to 270
drewp@bigasterisk.com
parents: 216
diff changeset
3 from light9.namespaces import L9
216
233ee9b1e561 checked the showconfig patch and fixed bugs
drewp@bigasterisk.com
parents: 215
diff changeset
4 from light9 import showconfig
211
9b360ee8636e move patchdata into show/, pull out curve.py from curvecalc, more networking.py unification
drewp@bigasterisk.com
parents: 210
diff changeset
5
334
42e4c4728a66 ascoltami, subcomposer, keyboardcomposer use rdf show data; raise channel count to 270
drewp@bigasterisk.com
parents: 216
diff changeset
6
85
174b35926067 converts subs from dicts to tab-sep-values and back again
drewp
parents: 42
diff changeset
7 def resolve_name(channelname):
174b35926067 converts subs from dicts to tab-sep-values and back again
drewp
parents: 42
diff changeset
8 "Ensure that we're talking about the primary name of the light."
174b35926067 converts subs from dicts to tab-sep-values and back again
drewp
parents: 42
diff changeset
9 return get_channel_name(get_dmx_channel(channelname))
174b35926067 converts subs from dicts to tab-sep-values and back again
drewp
parents: 42
diff changeset
10
174b35926067 converts subs from dicts to tab-sep-values and back again
drewp
parents: 42
diff changeset
11 def get_all_channels():
174b35926067 converts subs from dicts to tab-sep-values and back again
drewp
parents: 42
diff changeset
12 """returns primary names for all channels (sorted)"""
174b35926067 converts subs from dicts to tab-sep-values and back again
drewp
parents: 42
diff changeset
13 prinames = reverse_patch.values()[:]
174b35926067 converts subs from dicts to tab-sep-values and back again
drewp
parents: 42
diff changeset
14 prinames.sort()
174b35926067 converts subs from dicts to tab-sep-values and back again
drewp
parents: 42
diff changeset
15 return prinames
174b35926067 converts subs from dicts to tab-sep-values and back again
drewp
parents: 42
diff changeset
16
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
17 def get_dmx_channel(name):
45b12307c695 Initial revision
drewp
parents:
diff changeset
18 if name in patch:
45b12307c695 Initial revision
drewp
parents:
diff changeset
19 return patch[name]
45b12307c695 Initial revision
drewp
parents:
diff changeset
20
45b12307c695 Initial revision
drewp
parents:
diff changeset
21 try:
45b12307c695 Initial revision
drewp
parents:
diff changeset
22 i = int(name)
45b12307c695 Initial revision
drewp
parents:
diff changeset
23 return i
45b12307c695 Initial revision
drewp
parents:
diff changeset
24 except ValueError:
349
768d0d12c3a4 patch now reads new style rdf. Test cases!
Drew Perttula <drewp@bigasterisk.com>
parents: 334
diff changeset
25 raise ValueError("Invalid channel name: %r" % name)
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
26
45b12307c695 Initial revision
drewp
parents:
diff changeset
27 def get_channel_name(dmxnum):
349
768d0d12c3a4 patch now reads new style rdf. Test cases!
Drew Perttula <drewp@bigasterisk.com>
parents: 334
diff changeset
28 """if you pass a name, it will get normalized"""
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
29 try:
45b12307c695 Initial revision
drewp
parents:
diff changeset
30 return reverse_patch[dmxnum]
45b12307c695 Initial revision
drewp
parents:
diff changeset
31 except KeyError:
45b12307c695 Initial revision
drewp
parents:
diff changeset
32 return str(dmxnum)
45b12307c695 Initial revision
drewp
parents:
diff changeset
33
349
768d0d12c3a4 patch now reads new style rdf. Test cases!
Drew Perttula <drewp@bigasterisk.com>
parents: 334
diff changeset
34 def get_channel_uri(name):
768d0d12c3a4 patch now reads new style rdf. Test cases!
Drew Perttula <drewp@bigasterisk.com>
parents: 334
diff changeset
35 return uri_map[name]
768d0d12c3a4 patch now reads new style rdf. Test cases!
Drew Perttula <drewp@bigasterisk.com>
parents: 334
diff changeset
36
399
40b6a06bd090 rework Effects.py to fix chase(). now uses chase lists from config.n3
Drew Perttula <drewp@bigasterisk.com>
parents: 349
diff changeset
37 def dmx_from_uri(uri):
40b6a06bd090 rework Effects.py to fix chase(). now uses chase lists from config.n3
Drew Perttula <drewp@bigasterisk.com>
parents: 349
diff changeset
38 return uri_patch[uri]
40b6a06bd090 rework Effects.py to fix chase(). now uses chase lists from config.n3
Drew Perttula <drewp@bigasterisk.com>
parents: 349
diff changeset
39
129
f2eb20a52555 tiny cleanups and reload on import
dmcc
parents: 85
diff changeset
40 def reload_data():
399
40b6a06bd090 rework Effects.py to fix chase(). now uses chase lists from config.n3
Drew Perttula <drewp@bigasterisk.com>
parents: 349
diff changeset
41 global patch, reverse_patch, uri_map, uri_patch
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
42 patch = {}
45b12307c695 Initial revision
drewp
parents:
diff changeset
43 reverse_patch = {}
349
768d0d12c3a4 patch now reads new style rdf. Test cases!
Drew Perttula <drewp@bigasterisk.com>
parents: 334
diff changeset
44 uri_map = {}
399
40b6a06bd090 rework Effects.py to fix chase(). now uses chase lists from config.n3
Drew Perttula <drewp@bigasterisk.com>
parents: 349
diff changeset
45 uri_patch = {}
334
42e4c4728a66 ascoltami, subcomposer, keyboardcomposer use rdf show data; raise channel count to 270
drewp@bigasterisk.com
parents: 216
diff changeset
46
42e4c4728a66 ascoltami, subcomposer, keyboardcomposer use rdf show data; raise channel count to 270
drewp@bigasterisk.com
parents: 216
diff changeset
47 graph = showconfig.getGraph()
42e4c4728a66 ascoltami, subcomposer, keyboardcomposer use rdf show data; raise channel count to 270
drewp@bigasterisk.com
parents: 216
diff changeset
48
42e4c4728a66 ascoltami, subcomposer, keyboardcomposer use rdf show data; raise channel count to 270
drewp@bigasterisk.com
parents: 216
diff changeset
49 for chan in graph.subjects(RDF.type, L9['Channel']):
349
768d0d12c3a4 patch now reads new style rdf. Test cases!
Drew Perttula <drewp@bigasterisk.com>
parents: 334
diff changeset
50 for which, name in enumerate([graph.label(chan)] +
768d0d12c3a4 patch now reads new style rdf. Test cases!
Drew Perttula <drewp@bigasterisk.com>
parents: 334
diff changeset
51 list(graph.objects(chan, L9['altName']))):
768d0d12c3a4 patch now reads new style rdf. Test cases!
Drew Perttula <drewp@bigasterisk.com>
parents: 334
diff changeset
52 name = str(name)
768d0d12c3a4 patch now reads new style rdf. Test cases!
Drew Perttula <drewp@bigasterisk.com>
parents: 334
diff changeset
53 uri_map[name] = chan
768d0d12c3a4 patch now reads new style rdf. Test cases!
Drew Perttula <drewp@bigasterisk.com>
parents: 334
diff changeset
54
768d0d12c3a4 patch now reads new style rdf. Test cases!
Drew Perttula <drewp@bigasterisk.com>
parents: 334
diff changeset
55 if name in patch:
768d0d12c3a4 patch now reads new style rdf. Test cases!
Drew Perttula <drewp@bigasterisk.com>
parents: 334
diff changeset
56 raise ValueError("channel name %r used multiple times" % name)
768d0d12c3a4 patch now reads new style rdf. Test cases!
Drew Perttula <drewp@bigasterisk.com>
parents: 334
diff changeset
57 for output in graph.objects(chan, L9['output']):
768d0d12c3a4 patch now reads new style rdf. Test cases!
Drew Perttula <drewp@bigasterisk.com>
parents: 334
diff changeset
58 for addr in graph.objects(output, L9['dmxAddress']):
768d0d12c3a4 patch now reads new style rdf. Test cases!
Drew Perttula <drewp@bigasterisk.com>
parents: 334
diff changeset
59 addrInt = int(addr)
768d0d12c3a4 patch now reads new style rdf. Test cases!
Drew Perttula <drewp@bigasterisk.com>
parents: 334
diff changeset
60 patch[name] = addrInt
399
40b6a06bd090 rework Effects.py to fix chase(). now uses chase lists from config.n3
Drew Perttula <drewp@bigasterisk.com>
parents: 349
diff changeset
61 uri_patch[chan] = addrInt
40b6a06bd090 rework Effects.py to fix chase(). now uses chase lists from config.n3
Drew Perttula <drewp@bigasterisk.com>
parents: 349
diff changeset
62
349
768d0d12c3a4 patch now reads new style rdf. Test cases!
Drew Perttula <drewp@bigasterisk.com>
parents: 334
diff changeset
63 if which == 0:
768d0d12c3a4 patch now reads new style rdf. Test cases!
Drew Perttula <drewp@bigasterisk.com>
parents: 334
diff changeset
64 reverse_patch[addrInt] = name
768d0d12c3a4 patch now reads new style rdf. Test cases!
Drew Perttula <drewp@bigasterisk.com>
parents: 334
diff changeset
65 reverse_patch[addr] = name
768d0d12c3a4 patch now reads new style rdf. Test cases!
Drew Perttula <drewp@bigasterisk.com>
parents: 334
diff changeset
66 norm_name = name
768d0d12c3a4 patch now reads new style rdf. Test cases!
Drew Perttula <drewp@bigasterisk.com>
parents: 334
diff changeset
67 else:
768d0d12c3a4 patch now reads new style rdf. Test cases!
Drew Perttula <drewp@bigasterisk.com>
parents: 334
diff changeset
68 reverse_patch[name] = norm_name
129
f2eb20a52555 tiny cleanups and reload on import
dmcc
parents: 85
diff changeset
69
f2eb20a52555 tiny cleanups and reload on import
dmcc
parents: 85
diff changeset
70 # importing patch will load initial data
f2eb20a52555 tiny cleanups and reload on import
dmcc
parents: 85
diff changeset
71 reload_data()
f2eb20a52555 tiny cleanups and reload on import
dmcc
parents: 85
diff changeset
72