From f60ef36a6de1cbdde7cedae8b16bdaccdac26549 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Wed, 20 Oct 2010 18:47:01 +0000 Subject: Better RDF library abstraction (just use URIs, don't depend on node object style). --- lv2include/lv2include.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'lv2include') diff --git a/lv2include/lv2include.py b/lv2include/lv2include.py index f4b9b3c..5a8900b 100755 --- a/lv2include/lv2include.py +++ b/lv2include/lv2include.py @@ -35,15 +35,22 @@ import sys import RDF def rdf_load(uri): + "Load an RDF model" model = RDF.Model() parser = RDF.Parser(name="guess") parser.parse_into_model(model, uri) return model -def rdf_find(model, s, p, o): - return model.find_statements(RDF.Statement(s, p, o)) +def rdf_find_type(model, rdf_type): + "Return a list of the URIs of all resources in model with a given type" + results = model.find_statements(RDF.Statement(None, rdf.type, rdf_type)) + ret = [] + for r in results: + ret.append(str(r.subject.uri)) + return ret def rdf_namespace(uri): + "Create a new RDF namespace" return RDF.NS(uri) rdf = rdf_namespace('http://www.w3.org/1999/02/22-rdf-syntax-ns#') @@ -96,9 +103,8 @@ def build_tree(search_path, outdir): manifest = rdf_load('file://' + os.path.join(bundle, 'manifest.ttl')) # Query extension URI - results = rdf_find(manifest, None, rdf.type, lv2.Specification) - for r in results: - ext_uri = str(r.subject.uri) + specs = rdf_find_type(manifest, lv2.Specification) + for ext_uri in specs: ext_scheme = ext_uri[0:ext_uri.find(':')] ext_path = os.path.normpath(ext_uri[ext_uri.find(':') + 1:].lstrip('/')) ext_dir = os.path.join(outdir, ext_scheme, ext_path) -- cgit v1.2.1