Changeset - 1ba1d46a70a2
[Not reviewed]
default
0 4 0
Drew Perttula - 8 years ago 2017-05-24 08:26:39
drewp@bigasterisk.com
put song: prefix into song files
Ignore-this: 50e8d3947e925aa3edff31ed9d893b50
4 files changed with 14 insertions and 8 deletions:
0 comments (0 inline, 0 general)
bin/effecteval
Show inline comments
 
@@ -65,12 +65,13 @@ class SongEffects(PrettyErrorHandler, cy
 
        event = self.get_argument('event', default='default')
 
            
 
        log.info("adding to %s", song)
 

	
 
        p = yield songEffectPatch(self.settings.graph, dropped, song, event, ctx=song)
 
        self.settings.graph.patch(p)
 
        self.settings.graph.suggestPrefixes({'song': URIRef(song + '/')})
 
        
 
class SongEffectsUpdates(cyclone.websocket.WebSocketHandler):
 
    def connectionMade(self, *args, **kwargs):
 
        self.graph = self.settings.graph
 
        self.graph.addHandler(self.updateClient)
 
        
bin/rdfdb
Show inline comments
 
@@ -177,15 +177,16 @@ class WsClient(object):
 
class WatchedFiles(object):
 
    """
 
    find files, notice new files.
 

	
 
    This object watches directories. Each GraphFile watches its own file.
 
    """
 
    def __init__(self, dirUriMap, patch, getSubgraph):
 
    def __init__(self, dirUriMap, patch, getSubgraph, addlPrefixes=None):
 
        self.dirUriMap = dirUriMap # {abspath : uri prefix}
 
        self.patch, self.getSubgraph = patch, getSubgraph
 
        self.addlPrefixes = addlPrefixes
 
        
 
        self.graphFiles = {} # context uri : GraphFile
 
        
 
        self.notifier = INotify()
 
        self.notifier.startReading()
 
        
 
@@ -236,13 +237,14 @@ class WatchedFiles(object):
 
        # it.
 
        if inFile.endswith("config.n3"):
 
            return
 
            
 
        ctx = uriFromFile(self.dirUriMap, inFile)
 
        gf = GraphFile(self.notifier, inFile, ctx,
 
                       self.patch, self.getSubgraph)
 
                       self.patch, self.getSubgraph,
 
                       addlPrefixes=self.addlPrefixes)
 
        self.graphFiles[ctx] = gf
 
        log.info("%s do initial read", inFile)
 
        gf.reread()
 

	
 
    def aboutToPatch(self, ctx):
 
        """
 
@@ -259,13 +261,14 @@ class WatchedFiles(object):
 

	
 
        if ctx not in self.graphFiles:
 
            outFile = fileForUri(self.dirUriMap, ctx)
 
            assert '//' not in outFile, (outFile, self.dirUriMap, ctx)
 
            log.info("starting new file %r", outFile)
 
            self.graphFiles[ctx] = GraphFile(self.notifier, outFile, ctx,
 
                                             self.patch, self.getSubgraph)
 
                                             self.patch, self.getSubgraph,
 
                                             addlPrefixes=self.addlPrefixes)
 

	
 
    def dirtyFiles(self, ctxs):
 
        """mark dirty the files that we watch in these contexts.
 

	
 
        the ctx might not be a file that we already read; it might be
 
        for a new file we have to create, or it might be for a
 
@@ -279,19 +282,19 @@ class WatchedFiles(object):
 

	
 
        
 
class Db(object):
 
    """
 
    the master graph, all the connected clients, all the files we're watching
 
    """
 
    def __init__(self, dirUriMap):
 
    def __init__(self, dirUriMap, addlPrefixes=None):
 
      
 
        self.clients = []
 
        self.graph = ConjunctiveGraph()
 

	
 
        self.watchedFiles = WatchedFiles(dirUriMap,
 
                                         self.patch, self.getSubgraph)
 
                                         self.patch, self.getSubgraph, addlPrefixes)
 
        
 
        self.summarizeToLog()
 

	
 
    def patch(self, p, dueToFileChange=False):
 
        """
 
        apply this patch to the master graph then notify everyone about it
 
@@ -463,13 +466,14 @@ if __name__ == "__main__":
 
                      help="logging.DEBUG")
 
    (options, args) = parser.parse_args()
 

	
 
    log.setLevel(logging.DEBUG if options.verbose else logging.INFO)
 

	
 
    db = Db(dirUriMap={os.environ['LIGHT9_SHOW'].rstrip('/') + '/':
 
                       showconfig.showUri() + '/'})
 
                       showconfig.showUri() + '/'},
 
            addlPrefixes={'show': URIRef(showconfig.showUri() + '/')})
 

	
 
    from twisted.python import log as twlog
 
    twlog.startLogging(sys.stdout)
 

	
 
    reactor.listenTCP(networking.rdfdb.port, cyclone.web.Application(handlers=[
 
        (r'/live', Live),
light9/rdfdb/graphfile.py
Show inline comments
 
@@ -60,13 +60,13 @@ def patchN3SerializerToUseLessWhitespace
 
patchN3SerializerToUseLessWhitespace()
 

	
 
class GraphFile(object):
 
    """
 
    one rdf file that we read from, write to, and notice external changes to
 
    """
 
    def __init__(self, notifier, path, uri, patch, getSubgraph):
 
    def __init__(self, notifier, path, uri, patch, getSubgraph, addlPrefixes=None):
 
        """
 
        uri is the context for the triples in this file. We assume
 
        sometimes that we're the only ones with triples in this
 
        context.
 
        
 
        this does not include an initial reread() call
 
@@ -81,12 +81,14 @@ class GraphFile(object):
 
            'rdf': 'http://www.w3.org/1999/02/22-rdf-syntax-ns#',
 
            'rdfs': 'http://www.w3.org/2000/01/rdf-schema#',
 
            'xsd': 'http://www.w3.org/2001/XMLSchema#',
 
            'effect': 'http://light9.bigasterisk.com/effect/',
 
            'dev': 'http://light9.bigasterisk.com/device/',
 
        }
 
        if addlPrefixes:
 
            self.namespaces.update(addlPrefixes)
 
        
 
        if not os.path.exists(path):
 
            # can't start notify until file exists
 
            try:
 
                os.makedirs(os.path.dirname(path))
 
            except OSError:
light9/rdfdb/syncedgraph.py
Show inline comments
 
@@ -123,13 +123,12 @@ class SyncedGraph(CurrentStateGraphApi, 
 
        self.runDepsOnNewPatch(p)
 
        log.debug('sendPatch')
 
        self._sender.sendPatch(p).addErrback(self.sendFailed)
 
        log.debug('patch is done %s', debugKey)
 

	
 
    def suggestPrefixes(self, prefixes):
 
        song note edit should put song: to the song uri
 
        self.addlPrefixes.update(prefixes)
 

	
 
    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)