Changeset - 6ce00faec207
[Not reviewed]
default
0 2 0
Drew Perttula - 11 years ago 2014-06-01 10:39:17
drewp@bigasterisk.com
move sequentialUri to the graph lib
Ignore-this: 3dc3fb4833a23a46b8cfea90788f25be
2 files changed with 19 insertions and 7 deletions:
0 comments (0 inline, 0 general)
bin/effecteval
Show inline comments
 
@@ -22,39 +22,39 @@ from cycloneerr import PrettyErrorHandle
 

	
 
class EffectEdit(PrettyErrorHandler, cyclone.web.RequestHandler):
 
    def get(self):
 
        self.write(open("light9/effecteval/effect.html").read())
 
    def delete(self):
 
        graph = self.settings.graph
 
        uri = URIRef(self.get_argument('uri'))
 
        with graph.currentState(tripleFilter=(None, L9['effect'], uri)) as g:
 
            song = ctx = list(g.subjects(L9['effect'], uri))[0]
 
        self.settings.graph.patch(Patch(delQuads=[
 
            (song, L9['effect'], uri, ctx),
 
            ]))
 

	
 
        
 
class SongEffects(PrettyErrorHandler, cyclone.web.RequestHandler):
 
    def post(self):
 
        song = URIRef(self.get_argument('uri'))
 
        drop = URIRef(self.get_argument('drop'))
 
        ctx = song
 
        now = time.time()
 
        effect = song + "/effect/e-%f" % now
 
        curve = song + "/curve/c-%f" % now
 
        graph = self.settings.graph
 
        effect = graph.sequentialUri(song + "/effect/e-")
 
        curve = graph.sequentialUri(song + "/curve/c-")
 

	
 
        with self.settings.graph.currentState(
 
        with graph.currentState(
 
                tripleFilter=(drop, RDFS.label, None)) as g:
 
            dropSubLabel = g.label(drop)
 
        
 
        self.settings.graph.patch(Patch(addQuads=[
 
        graph.patch(Patch(addQuads=[
 
            (song, L9['curve'], curve, ctx),
 
            (song, L9['effect'], effect, ctx),
 
            (effect, RDF.type, L9['Effect'], ctx),
 
            (effect, L9['code'],
 
             Literal('out = sub(%s, intensity=%s)' % (drop.n3(), curve.n3())),
 
             ctx),
 
            (curve, RDF.type, L9['Curve'], ctx),
 
            (curve, RDFS.label, Literal('sub %s' % dropSubLabel), ctx),
 
            (curve, L9['points'], Literal('0 0'), ctx),
 
            ]))
 
        
 
class SongEffectsUpdates(cyclone.websocket.WebSocketHandler):
light9/rdfdb/currentstategraphapi.py
Show inline comments
 
import logging, traceback, time
 
import logging, traceback, time, itertools
 
from rdflib import ConjunctiveGraph
 
from light9.rdfdb.rdflibpatch import contextsForStatement as rp_contextsForStatement
 
log = logging.getLogger("currentstate")
 

	
 
class CurrentStateGraphApi(object):
 
    """
 
    mixin for SyncedGraph, separated here because these methods work together
 
    """
 

	
 
    def currentState(self, context=None, tripleFilter=(None, None, None)):
 
        """
 
        a graph you can read without being in an addHandler
 
@@ -39,16 +39,28 @@ class CurrentStateGraphApi(object):
 
            def logThisCopy(self, g, sec):
 
                log.info("copied graph %s statements (%.1f ms) "
 
                         "because of this:" % (len(g), sec * 1000))
 
                for frame in traceback.format_stack(limit=4)[:-2]:
 
                    for line in frame.splitlines():
 
                        log.info("  "+line)
 

	
 
            def __exit__(self, type, val, tb):
 
                return
 

	
 
        return Mgr()
 

	
 
    def sequentialUri(self, prefix):
 
        """
 
        Prefix URIRef like http://example.com/r- will return
 
        http://example.com/r-1 if that uri is not a subject in the graph,
 
        or else http://example.com/r-2, etc
 
        """
 
        for i in itertools.count(1):
 
            newUri = prefix + str(i)
 
            if not list(self._grap.triples((newUri, None, None))):
 
                return newUri
 

	
 
        
 
def contextsForStatementNoWildcards(g, triple):
 
    if None in triple:
 
        raise NotImplementedError("no wildcards")
 
    return rp_contextsForStatement(g, triple)
0 comments (0 inline, 0 general)