Changeset - 4b9997ab0e4f
[Not reviewed]
default
0 4 0
Drew Perttula - 12 years ago 2013-06-10 09:58:59
drewp@bigasterisk.com
push some logs down to debug. -v flag on SC. another tripleFilter optimization
Ignore-this: 41de7e838ff6c775ee4e350f4dfa141d
4 files changed with 11 insertions and 7 deletions:
0 comments (0 inline, 0 general)
bin/subcomposer
Show inline comments
 
@@ -100,27 +100,27 @@ class Subcomposer(tk.Frame):
 
            self.currentSub(Submaster.PersistentSubmaster(graph, s))
 

	
 
        @self.currentSub.subscribe
 
        def subChanged(newSub):
 
            if newSub is None:
 
                graph.patchObject(self.session,
 
                                  self.session, L9['currentSub'], None)
 
                return
 
            self.sendupdate()
 
            graph.patchObject(self.session,
 
                              self.session, L9['currentSub'], newSub.uri)
 

	
 
            with graph.currentState() as current:
 
                
 
                if newSub and (newSub.uri, RDF.type, L9['LocalSubmaster']) in current:
 
            localStmt = (newSub.uri, RDF.type, L9['LocalSubmaster'])
 
            with graph.currentState(tripleFilter=localStmt) as current:
 
                if newSub and localStmt in current:
 
                    self._currentChoice(Local)
 
                else:
 
                    # i think right here is the point that the last local
 
                    # becomes garbage, and we could clean it up. 
 
                    self._currentChoice(newSub.uri)
 

	
 
        dispatcher.connect(self.levelsChanged, "sub levels changed")
 
            
 
        @self._currentChoice.subscribe
 
        def choiceChanged(newChoice):
 
            if newChoice is Local:
 
                newChoice = self.makeLocal()
 
@@ -187,27 +187,31 @@ def launch(opts, args, root, graph, sess
 
        graph.patchObject(session,
 
                          session, L9['currentSub'], URIRef(args[0]))
 

	
 
    task.LoopingCall(sc.sendupdate).start(10)
 

	
 

	
 
#############################
 

	
 
if __name__ == "__main__":
 
    parser = OptionParser(usage="%prog [suburi]")
 
    parser.add_option('--no-geometry', action='store_true',
 
                      help="don't save/restore window geometry")
 
    parser.add_option('-v', action='store_true', help="log debug level")
 

	
 
    clientsession.add_option(parser)
 
    opts, args = parser.parse_args()
 

	
 
    log.setLevel(logging.DEBUG if opts.v else logging.INFO)
 
    
 
    root=tk.Tk()
 
    root.config(bg='black')
 
    root.tk_setPalette("#004633")
 

	
 
    initTkdnd(root.tk, 'tkdnd/trunk/')
 

	
 
    graph = SyncedGraph("subcomposer")
 
    session = clientsession.getUri('subcomposer', opts)
 

	
 
    graph.initiallySynced.addCallback(lambda _: launch(opts, args, root, graph, session))
 

	
 
    root.protocol('WM_DELETE_WINDOW', reactor.stop)
light9/Submaster.py
Show inline comments
 
@@ -139,29 +139,29 @@ class PersistentSubmaster(Submaster):
 

	
 
    def ident(self):
 
        return self.uri
 

	
 
    def _editedLevels(self):
 
        self.save()
 

	
 
    def setName(self):
 
        log.info("sub update name %s %s", self.uri, self.graph.label(self.uri))
 
        self.name = self.graph.label(self.uri)
 

	
 
    def setLevels(self):
 
        log.info("sub update levels")
 
        log.debug("sub update levels")
 
        oldLevels = getattr(self, 'levels', {}).copy()
 
        self.setLevelsFromGraph()
 
        if oldLevels != self.levels:
 
            log.info("sub %s changed" % self.name)
 
            log.debug("sub %s changed" % self.name)
 
            # dispatcher too? this would help subcomposer
 
            dispatcher.send("sub levels changed", sub=self)
 

	
 
    def setLevelsFromGraph(self):
 
        if hasattr(self, 'levels'):
 
            self.levels.clear()
 
        else:
 
            self.levels = {}
 
        for lev in self.graph.objects(self.uri, L9['lightLevel']):
 
            log.debug(" lightLevel %s %s", self.uri, lev)
 
            chan = self.graph.value(lev, L9['channel'])
 

	
light9/rdfdb/patchsender.py
Show inline comments
 
@@ -32,25 +32,25 @@ class PatchSender(object):
 
        self._patchesToSend[:] = []
 
        # we might be in the middle of a post; ideally that would be
 
        # aborted, too. Since that's not coded yet, or it might be too late to
 
        # abort, what should happen?
 
        # 1. this could return deferred until we think our posts have stopped
 
        # 2. or, other code could deal for the fact that cancelAll
 
        # isn't perfect
 

	
 
    def _continueSending(self):
 
        if not self._patchesToSend or self._currentSendPatchRequest:
 
            return
 
        if len(self._patchesToSend) > 1:
 
            log.info("%s patches left to send", len(self._patchesToSend))
 
            log.debug("%s patches left to send", len(self._patchesToSend))
 
            # this is where we could concatenate little patches into a
 
            # bigger one. Often, many statements will cancel each
 
            # other out. not working yet:
 
            if 0:
 
                p = self._patchesToSend[0].concat(self._patchesToSend[1:])
 
                print "concat down to"
 
                print 'dels'
 
                for q in p.delQuads: print q
 
                print 'adds'
 
                for q in p.addQuads: print q
 
                print "----"
 
            else:
light9/rdfdb/syncedgraph.py
Show inline comments
 
@@ -97,25 +97,25 @@ class SyncedGraph(CurrentStateGraphApi, 
 

	
 
    def patch(self, p):
 
        """send this patch to the server and apply it to our local
 
        graph and run handlers"""
 

	
 
        if p.isNoop():
 
            log.info("skipping no-op patch")
 
            return
 
        
 
        # these could fail if we're out of sync. One approach:
 
        # Rerequest the full state from the server, try the patch
 
        # again after that, then give up.
 
        log.info("del %s add %s", [q[2] for q in p.delQuads], [q[2] for q in  p.addQuads])
 
        log.debug("del %s add %s", [q[2] for q in p.delQuads], [q[2] for q in  p.addQuads])
 
        try:
 
            patchQuads(self._graph, p.delQuads, p.addQuads, perfect=True)
 
        except ValueError:
 
            self.sendFailed(None)
 
            return
 
        self.runDepsOnNewPatch(p)
 
        self._sender.sendPatch(p).addErrback(self.sendFailed)
 

	
 
    def sendFailed(self, result):
 
        """
 
        we asked for a patch to be queued and sent to the master, and
 
        that ultimately failed because of a conflict
0 comments (0 inline, 0 general)