Mercurial > code > home > repos > light9
changeset 570:5037fa2c9983
fix how KC reads its graphs. switch to logging lib and add -v flag
Ignore-this: f16eb2408c6a56c41e086567c749b64a
author | drewp@bigasterisk.com |
---|---|
date | Sat, 19 Jun 2010 22:24:39 +0000 |
parents | 44f8294c5bcf |
children | eb6f7a28034b |
files | bin/keyboardcomposer light9/Submaster.py |
diffstat | 2 files changed, 23 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/bin/keyboardcomposer Sat Jun 19 22:00:53 2010 +0000 +++ b/bin/keyboardcomposer Sat Jun 19 22:24:39 2010 +0000 @@ -1,7 +1,7 @@ #!/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 @@ 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()
--- a/light9/Submaster.py Sat Jun 19 22:00:53 2010 +0000 +++ b/light9/Submaster.py Sat Jun 19 22:24:39 2010 +0000 @@ -1,5 +1,5 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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()