changeset 928:d9fd4725c453

just logging improvements Ignore-this: 821759b35224a65628557c2cfd713b54
author Drew Perttula <drewp@bigasterisk.com>
date Tue, 11 Jun 2013 20:09:45 +0000
parents 7ff5516a0681
children c20c2eea6fce
files light9/rdfdb/graphfile.py light9/rdfdb/patch.py light9/rdfdb/syncedgraph.py
diffstat 3 files changed, 33 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/light9/rdfdb/graphfile.py	Tue Jun 11 06:11:58 2013 +0000
+++ b/light9/rdfdb/graphfile.py	Tue Jun 11 20:09:45 2013 +0000
@@ -53,11 +53,16 @@
     def notify(self, notifier, filepath, mask):
         maskNames = humanReadableMask(mask)
         if maskNames[0] == 'delete_self':
-            log.warn("%s delete_self event: need to dump the stmts from "
-                     "this file", filepath)
-            # this is happening surprisingly often, even to files that
-            # are still there
+            if not filepath.exists():
+                log.warn("%s delete_self event: need to dump the stmts from "
+                         "this file", filepath)
+            else:
+                log.warn("%s delete_self event but file is here. ignoring",
+                         filepath)
             return
+
+        # we could filter these out in the watch() call, but I want
+        # the debugging
         if maskNames[0] in ['open', 'access', 'close_nowrite', 'attrib']:
             log.debug("%s %s event, ignoring" % (filepath, maskNames))
             return
--- a/light9/rdfdb/patch.py	Tue Jun 11 06:11:58 2013 +0000
+++ b/light9/rdfdb/patch.py	Tue Jun 11 20:09:45 2013 +0000
@@ -1,5 +1,6 @@
 import json, unittest
-from rdflib import ConjunctiveGraph, Graph, URIRef, URIRef as U
+from rdflib import ConjunctiveGraph, Graph, URIRef, URIRef as U, Literal
+from light9.namespaces import XSD
 from light9.rdfdb.rdflibpatch import graphFromNQuad, graphFromQuads, serializeQuad
 
 ALLSTMTS = (None, None, None)
@@ -40,6 +41,25 @@
             self._addGraph = graphFromNQuad(body['patch']['adds'])
             if 'senderUpdateUri' in body:
                 self.senderUpdateUri = body['senderUpdateUri']
+
+    def __str__(self):
+        def shorten(n):
+            if isinstance(n, Literal):
+                if n.datatype == XSD['double']:
+                    return str(n.toPython())
+            if isinstance(n, URIRef):
+                for long, short in [
+                        ("http://light9.bigasterisk.com/", "l9"),
+                        
+                ]:
+                    if n.startswith(long):
+                        return short+":"+n[len(long):]
+            return n.n3()
+        def formatQuad(quad):
+            return " ".join(shorten(n) for n in quad)
+        delLines = ["  -%s" % formatQuad(q) for q in self.delQuads]
+        addLines = ["  +%s" % formatQuad(q) for q in self.addQuads]
+        return "\nPatch:\n" + "\n".join(delLines) + "\n" + "\n".join(addLines)
                 
     @classmethod
     def fromDiff(cls, oldGraph, newGraph):
--- a/light9/rdfdb/syncedgraph.py	Tue Jun 11 06:11:58 2013 +0000
+++ b/light9/rdfdb/syncedgraph.py	Tue Jun 11 20:09:45 2013 +0000
@@ -106,10 +106,11 @@
         # 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.debug("del %s add %s", [q[2] for q in p.delQuads], [q[2] for q in  p.addQuads])
+        log.debug("apply local patch %s", p)
         try:
             patchQuads(self._graph, p.delQuads, p.addQuads, perfect=True)
-        except ValueError:
+        except ValueError as e:
+            log.error(e)
             self.sendFailed(None)
             return
         self.runDepsOnNewPatch(p)