changeset 349:768d0d12c3a4

patch now reads new style rdf. Test cases!
author Drew Perttula <drewp@bigasterisk.com>
date Sun, 10 Jun 2007 06:18:53 +0000
parents de32d979275b
children c7478a778992
files light9/Patch.py
diffstat 1 files changed, 24 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/light9/Patch.py	Sun Jun 10 04:43:35 2007 +0000
+++ b/light9/Patch.py	Sun Jun 10 06:18:53 2007 +0000
@@ -22,28 +22,44 @@
         i = int(name)
         return i
     except ValueError:
-        raise ValueError("Invalid channel name: %s" % name)
+        raise ValueError("Invalid channel name: %r" % name)
 
 def get_channel_name(dmxnum):
+    """if you pass a name, it will get normalized"""
     try:
         return reverse_patch[dmxnum]
     except KeyError:
         return str(dmxnum)
 
+def get_channel_uri(name):
+    return uri_map[name]
+
 def reload_data():
-    global patch, reverse_patch
+    global patch, reverse_patch, uri_map
     patch = {}
     reverse_patch = {}
+    uri_map = {}
 
     graph = showconfig.getGraph()
 
     for chan in graph.subjects(RDF.type, L9['Channel']):
-        name = graph.label(chan)
-        # int() shouldn't be required, but some code in subcomposer
-        # ignores channel numbers if they're not int
-        addr = int(graph.value(chan, L9['dmxAddress']))
-        patch[name] = addr
-        reverse_patch[addr] = name
+        for which, name in enumerate([graph.label(chan)] +
+                                     list(graph.objects(chan, L9['altName']))):
+            name = str(name)
+            uri_map[name] = chan
+
+            if name in patch:
+                raise ValueError("channel name %r used multiple times" % name)
+            for output in graph.objects(chan, L9['output']):
+                for addr in graph.objects(output, L9['dmxAddress']):
+                    addrInt = int(addr)
+                    patch[name] = addrInt
+                    if which == 0:
+                        reverse_patch[addrInt] = name
+                        reverse_patch[addr] = name
+                        norm_name = name
+                    else:
+                        reverse_patch[name] = norm_name
 
 # importing patch will load initial data
 reload_data()