Changeset - 5037fa2c9983
[Not reviewed]
default
0 2 0
drewp@bigasterisk.com - 15 years ago 2010-06-19 22:24:39
drewp@bigasterisk.com
fix how KC reads its graphs. switch to logging lib and add -v flag
Ignore-this: f16eb2408c6a56c41e086567c749b64a
2 files changed with 23 insertions and 13 deletions:
0 comments (0 inline, 0 general)
bin/keyboardcomposer
Show inline comments
 
#!/usr/bin/python
 

	
 
from __future__ import division, nested_scopes
 
import cgi, os, sys, time, subprocess
 
import cgi, os, sys, time, subprocess, logging
 
from optparse import OptionParser
 
import webcolors, colorsys
 

	
 
@@ -444,10 +444,13 @@ if __name__ == "__main__":
 
                      help="don't load or save levels")
 
    parser.add_option('--no-sliders', action='store_true',
 
                      help="don't attach to hardware sliders")
 
    parser.add_option('-v', action='store_true', help="log info level")
 
    opts, args = parser.parse_args()
 

	
 
    logging.basicConfig(level=logging.INFO if opts.v else logging.WARN)
 
    log = logging.getLogger()
 

	
 
    graph = showconfig.getGraph()
 
    
 
    s = Submasters(graph)
 

	
 
    root = Tk()
light9/Submaster.py
Show inline comments
 
from __future__ import division
 
import os
 
import os, logging
 
from rdflib.Graph import Graph
 
from rdflib import RDFS, Literal, BNode
 
from light9.namespaces import L9, XSD
 
@@ -9,6 +9,7 @@ try:
 
    import dispatch.dispatcher as dispatcher
 
except ImportError:
 
    from louie import dispatcher
 
log = logging.getLogger()
 

	
 
class Submaster:
 
    "Contain a dictionary of levels, but you didn't need to know that"
 
@@ -55,7 +56,8 @@ class Submaster:
 
            self.reload(quiet=True, graph=graph)
 
        if not self.temporary:
 
            dispatcher.connect(self.reload, 'reload all subs')
 
            
 
        log.info("%s initial levels %s", self.name, self.levels)
 
        
 
    def reload(self, quiet=False, graph=None):
 
        if self.temporary:
 
            return
 
@@ -63,26 +65,31 @@ class Submaster:
 
            oldlevels = self.levels.copy()
 
            self.levels.clear()
 
            patchGraph = showconfig.getGraph()
 
            if graph is None:
 
            if 1 or graph is None:
 
                # need to read the sub graph to build the levels, not
 
                # use the main one! The sub graphs will eventually
 
                # just be part of the one and only shared graph
 
                graph = Graph()
 
                graph.parse(showconfig.subFile(self.name), format="n3")
 
                inFile = showconfig.subFile(self.name)
 
                log.info("reading %s", inFile)
 
                graph.parse(inFile, format="n3")
 
            self.uri = L9['sub/%s' % self.name]
 
            for lev in graph.objects(self.uri, L9['lightLevel']):
 
                chan = graph.value(lev, L9['channel'])
 
                val = graph.value(lev, L9['level'])
 
                name = patchGraph.label(chan)
 
                if not name:
 
                    print "sub %r has channel %r with no name- leaving out that channel" % (self.name, chan)
 
                    log.error("sub %r has channel %r with no name- leaving out that channel" % (self.name, chan))
 
                    continue
 
                self.levels[name] = float(val)
 

	
 
            if (not quiet) and (oldlevels != self.levels):
 
                print "sub %s changed" % self.name
 
                log.info("sub %s changed" % self.name)
 
        except IOError, e:
 
            print "Can't read file for sub: %r (%s)" % (self.name, e)
 
            log.error("Can't read file for sub: %r (%s)" % (self.name, e))
 
    def save(self):
 
        if self.temporary:
 
            print "not saving temporary sub named",self.name
 
            log.info("not saving temporary sub named %s",self.name)
 
            return
 

	
 
        graph = Graph()
 
@@ -92,7 +99,7 @@ class Submaster:
 
            try:
 
                chanUri = Patch.get_channel_uri(chan)
 
            except KeyError:
 
                print "saving dmx channels with no :Channel node is not supported yet. Give channel %s a URI for it to be saved. Omitting this channel from the sub." % chan
 
                log.error("saving dmx channels with no :Channel node is not supported yet. Give channel %s a URI for it to be saved. Omitting this channel from the sub." % chan)
 
                continue
 
            lev = BNode()
 
            graph.add((subUri, L9['lightLevel'], lev))
 
@@ -141,7 +148,7 @@ class Submaster:
 
            try:
 
                dmxchan = Patch.get_dmx_channel(k) - 1
 
            except ValueError:
 
                print "error trying to compute dmx levels for submaster %s" % self.name
 
                log.error("error trying to compute dmx levels for submaster %s" % self.name)
 
                raise
 
            if dmxchan >= len(levels):
 
                levels.extend([0] * (dmxchan - len(levels) + 1))
 
@@ -227,7 +234,7 @@ class Submasters:
 
               filename.startswith('CVS'):
 
                continue
 
            self.submasters[filename] = Submaster(filename, graph=graph)
 
        print "loaded subs", self.submasters
 
        log.info("loaded subs %s", self.submasters)
 
    def get_all_subs(self):
 
        "All Submaster objects"
 
        l = self.submasters.items()
0 comments (0 inline, 0 general)