Changeset - 1bda494a8c3a
[Not reviewed]
default
0 1 0
drewp@bigasterisk.com - 12 years ago 2013-06-05 23:44:33
drewp@bigasterisk.com
attempted fix for FilePath making paths absolute (when they need to stay relative since they're used in uris)
Ignore-this: 3bf04175136af9f1f7e823f875209303
1 file changed with 11 insertions and 9 deletions:
bin/rdfdb
11
9
0 comments (0 inline, 0 general)
bin/rdfdb
Show inline comments
 
@@ -190,68 +190,70 @@ class WatchedFiles(object):
 
                    for base in filenames:
 
                        self.watchFile(os.path.join(dirpath, base))
 
                    self.notifier.watch(FilePath(dirpath), autoAdd=True,
 
                                        callbacks=[self.dirChange])
 
        finally:
 
            self.initialLoad = False
 

	
 
    def dirChange(self, watch, path, mask):
 
        if mask & IN_CREATE:
 
            self.watchFile(path.path)
 
            
 
    def watchFile(self, inFile):
 
        """consider adding a GraphFile to self.graphFiles"""
 
        if not isinstance(inFile, FilePath):
 
            inFile = FilePath(inFile)
 
        if not inFile.isfile():
 
        """
 
        consider adding a GraphFile to self.graphFiles
 

	
 
        inFile needs to be a relative path, not an absolute (e.g. in a
 
        FilePath) because we use its exact relative form in the
 
        context URI
 
        """
 
        if not os.path.isfile(inFile):
 
            return
 
        if inFile.splitext()[1] not in ['.n3']:
 
        if os.path.splitext(inFile)[1] not in ['.n3']:
 
            return
 

	
 
        # an n3 file with rules makes it all the way past this reading
 
        # and the serialization. Then, on the receiving side, a
 
        # SyncedGraph calls graphFromNQuad on the incoming data and
 
        # has a parse error. I'm not sure where this should be fixed
 
        # yet.
 
        if '-rules' in inFile.path:
 
        if '-rules' in inFile:
 
            return
 
            
 
        ctx = self.uriFromFile(inFile)
 
        gf = GraphFile(self.notifier, inFile.path, ctx,
 
        gf = GraphFile(self.notifier, inFile, ctx,
 
                       self.patch, self.getSubgraph)
 
        self.graphFiles[ctx] = gf
 
        gf.reread()
 

	
 
    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
 
        transient context that we're not going to save
 

	
 
        if it's a ctx with no file, error
 
        """
 
        for ctx in ctxs:
 
            g = self.getSubgraph(ctx)
 

	
 
            if ctx not in self.graphFiles:
 
                outFile = self.fileForUri(ctx)
 
                self.graphFiles[ctx] = GraphFile(self.notifier, outFile, ctx,
 
                                                 self.patch, self.getSubgraph)
 
            
 
            self.graphFiles[ctx].dirty(g)
 

	
 
    def uriFromFile(self, filename):
 
        if isinstance(filename, FilePath):
 
            filename = filename.path
 
        assert filename.endswith('.n3'), filename
 
        return URIRef(self.topUri + filename[:-len('.n3')])
 

	
 
    def fileForUri(self, ctx):
 
        assert isinstance(ctx, URIRef), ctx
 
        if not ctx.startswith(self.topUri):
 
            raise ValueError("don't know what filename to use for %s" % ctx)
 
        return ctx[len(self.topUri):] + ".n3"
 

	
 
        
 
class Db(object):
 
    """
0 comments (0 inline, 0 general)