[SCM] calf/master: + Big Bull: added my little Python bull.... project in extremely early development stage
js at users.alioth.debian.org
js at users.alioth.debian.org
Tue May 7 15:37:18 UTC 2013
The following commit has been merged in the master branch:
commit 6f18409ecdc3a90fae4c8b8eb75fbfa2f959f903
Author: kfoltman <kfoltman at 78b06b96-2940-0410-b7fc-879d825d01d8>
Date: Fri Jun 13 23:25:11 2008 +0000
+ Big Bull: added my little Python bull.... project in extremely early development stage
git-svn-id: https://calf.svn.sourceforge.net/svnroot/calf/trunk@200 78b06b96-2940-0410-b7fc-879d825d01d8
diff --git a/bigbull/client.py b/bigbull/client.py
new file mode 100644
index 0000000..060b656
--- /dev/null
+++ b/bigbull/client.py
@@ -0,0 +1,61 @@
+import os
+import sys
+import fakeserv
+
+class CommandExec:
+ nextId = 1
+
+ def __init__(self, type, *args):
+ self.cmdId = CommandExec.nextId
+ self.nextId += 1
+ self.type = type
+ self.args = args
+ self.error = None
+ self.okHandlers = []
+ self.errorHandlers = []
+
+ def onOK(self, handler):
+ self.okHandlers.append(handler)
+
+ def onError(self, handler):
+ self.errorHandlers.append(handler)
+
+ def run(self):
+ fakeserv.queue(self)
+
+ def calledOnOK(self, result):
+ self.result = result
+ print "OK: %s(%s) -> %s" % (self.type, self.args, self.result)
+ for h in self.okHandlers:
+ h.receiveData(self)
+
+ def calledOnError(self, message):
+ self.error = message
+ print "Error: %s(%s) -> %s" % (self.type, self.args, message)
+ for h in self.errorHandlers:
+ h.receiveError(self)
+
+class LV2Plugin:
+ def __init__(self, uri):
+ self.uri = uri
+ self.name = uri
+ self.license = ""
+ self.ports = []
+ self.requiredFeatures = {}
+ self.optionalFeatures = {}
+
+ def decode(self, data):
+ self.name = data['doap:name']
+
+fakeserv.start()
+
+class URIListReceiver:
+ def receiveData(self, data):
+ #print "URI list received: " + repr(data.result)
+ for uri in data.result:
+ cmd = CommandExec('get_info', uri)
+ cmd.run()
+
+cmd = CommandExec('get_uris', 'http://lv2plug.in/ns/lv2core#')
+cmd.onOK(URIListReceiver())
+cmd.run()
diff --git a/bigbull/fakeserv.py b/bigbull/fakeserv.py
new file mode 100644
index 0000000..349382b
--- /dev/null
+++ b/bigbull/fakeserv.py
@@ -0,0 +1,143 @@
+import re
+import os
+import sys
+import glob
+import yappy.parser
+
+class DumpRDFModel:
+ def addTriple(self, s, p, o):
+ print "%s [%s] %s" % (s, p, repr(o))
+
+class SimpleRDFModel:
+ def __init__(self):
+ self.bySubject = {}
+ self.byPredicate = {}
+ def addTriple(self, s, p, o):
+ if s not in self.bySubject:
+ self.bySubject[s] = {}
+ if p not in self.bySubject[s]:
+ self.bySubject[s][p] = []
+ self.bySubject[s][p].append(o)
+ if p not in self.byPredicate:
+ self.byPredicate[p] = {}
+ if s not in self.byPredicate[p]:
+ self.byPredicate[p][s] = []
+ self.byPredicate[p][s].append(o)
+ def dump(self):
+ for s in self.bySubject.keys():
+ for p in self.bySubject[s].keys():
+ print "%s %s %s" % (s, p, self.bySubject[s][p])
+
+def parseTTL(uri, content, model):
+ prefixes = {}
+ lexer = yappy.parser.Lexer([
+ (r"(?m)^\s*#[^\n]*", ""),
+ ('"""(\n|\r|.)*?"""', lambda x : ("string", x[3:-3])),
+ (r'"([^"\\]|\\.)+"', lambda x : ("string", x[1:-1])),
+ (r"<>", lambda x : ("URI", uri)),
+ (r"<[^>]*>", lambda x : ("URI", x[1:-1])),
+ ("[-a-zA-Z0-9_]*:[-a-zA-Z0-9_]*", lambda x : ("prnot", x)),
+ ("@prefix", lambda x : ("prefix", x)),
+ (r"-?[0-9]+\.[0-9]+", lambda x : ("number", float(x))),
+ (r"-?[0-9]+", lambda x : ("number", int(x))),
+ ("[a-zA-Z0-9_]+", lambda x : ("symbol", x)),
+ (r"[\[\];.,]", lambda x : (x, x)),
+ ("\s+", ""),
+ ])
+ spo_stack = []
+ spo = ["", "", ""]
+ item = 0
+ anoncnt = 1
+ for x in lexer.scan(content):
+ if x[0] == '':
+ continue
+ if x[0] == 'prefix':
+ spo[0] = "@prefix"
+ item = 1
+ continue
+ elif (x[0] == '.' and spo_stack == []) or x[0] == ';' or x[0] == ',':
+ if item == 3:
+ if spo[0] == "@prefix":
+ prefixes[spo[1][:-1]] = spo[2]
+ else:
+ model.addTriple(spo[0], spo[1], spo[2])
+ if spo[1] == "a":
+ model.addTriple("$classes", spo[2], spo[0])
+ if x[0] == '.': item = 0
+ elif x[0] == ';': item = 1
+ elif x[0] == ',': item = 2
+ else:
+ print uri+": Unexpected " + x[0]
+ elif x[0] == "prnot" and item < 3:
+ prnot = x[1].split(":")
+ if item != 0 and spo[0] == "@prefix":
+ spo[item] = x[1]
+ else:
+ spo[item] = prefixes[prnot[0]] + prnot[1]
+ item += 1
+ elif (x[0] == 'URI' or x[0] == "string" or x[0] == "number" or (x[0] == "symbol" and x[1] == "a" and item == 1)) and (item < 3):
+ if x[0] == "URI" and x[1].find(":") == -1 and x[1][0] != "/":
+ # This is quite silly
+ x = ("URI", os.path.dirname(uri) + "/" + x[1])
+ spo[item] = x[1]
+ item += 1
+ elif x[0] == '[':
+ spo_stack.append(spo)
+ spo[0] = uri + "$anon$" + str(anoncnt)
+ item = 1
+ anoncnt += 1
+ elif x[0] == ']':
+ spo = spo_stack[-1]
+ spo_stack = spo_stack[:-1]
+ item = 3
+ else:
+ print uri + ": Unexpected: " + repr(x)
+
+class FakeServer(object):
+ def __init__(self):
+ self.initManifests()
+ #parseTTL("http://lv2plug.in/ns/lv2core#", file("/usr/lib/lv2/lv2core.lv2/lv2.ttl").read(), m)
+
+ def initManifests(self):
+ lv2path = ["/usr/lib/lv2", "/usr/local/lib/lv2"]
+ self.manifests = SimpleRDFModel()
+ self.paths = {}
+ self.plugin_info = dict()
+ for dir in lv2path:
+ for bundle in glob.iglob(dir + "/*.lv2"):
+ fn = bundle+"/manifest.ttl"
+ if os.path.exists(fn):
+ parseTTL(fn, file(fn).read(), self.manifests)
+ self.plugins = self.manifests.bySubject["$classes"]["http://lv2plug.in/ns/lv2core#Plugin"]
+
+ def get_uris(self, base_uri):
+ if base_uri == 'http://lv2plug.in/ns/lv2core#':
+ return self.plugins
+ raise StringException("Invalid base URI")
+
+ def get_info(self, uri):
+ if uri not in self.plugin_info:
+ world = SimpleRDFModel()
+ seeAlso = self.manifests.bySubject[uri]["http://www.w3.org/2000/01/rdf-schema#seeAlso"]
+ for doc in seeAlso:
+ # print "Loading " + doc
+ parseTTL(doc, file(doc).read(), world)
+ self.plugin_info[uri] = world
+ info = self.plugin_info[uri]
+ dest = {}
+ dest['name'] = info.bySubject[uri]['http://usefulinc.com/ns/doap#name'][0]
+ dest['license'] = info.bySubject[uri]['http://usefulinc.com/ns/doap#license'][0]
+ dest['classes'] = info.bySubject[uri]['http://usefulinc.com/ns/doap#license'][0]
+ return dest
+
+def start():
+ global instance
+ instance = FakeServer()
+
+def queue(cmdObject):
+ global instance
+ try:
+ cmdObject.calledOnOK(type(instance).__dict__[cmdObject.type](instance, *cmdObject.args))
+ except:
+ cmdObject.calledOnError(repr(sys.exc_info()))
+
diff --git a/bigbull/protocol.txt b/bigbull/protocol.txt
new file mode 100644
index 0000000..f13976a
--- /dev/null
+++ b/bigbull/protocol.txt
@@ -0,0 +1,13 @@
+There's just this much here. Proves again that it's just hand waving and little substance.
+
+protocol:
+asynchronous,
+commands will have sequence numbers
+a command that is completed returns ok command with serial no back, exception returns error command with serial no (duh)
+
+commands:
+
+allocate_ids(count) -> id_segment(first_id)
+get_uris(uri) -> uri_list([uri, uri, uri...])
+get_info(uri) -> uri_info(cmd_id, hash) hash = { 'requiredFeatures': {}, 'optionalFeatures' : {}, ports: [ { 'index' : 0, 'label' : 'blah', 'properties' : {}, } ]
+instantiate(cmd_id, id, uri) -> ok(cmd_id) | error(cmd_id, message)
--
calf audio plugins packaging
More information about the pkg-multimedia-commits
mailing list