From 2be75b8d22dedbc2b2d011700659552def2bc72b Mon Sep 17 00:00:00 2001 From: David Robillard Date: Wed, 20 Oct 2010 18:31:12 +0000 Subject: Abstract all RDF stuff into 3 functions. --- lv2include/lv2include.py | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'lv2include/lv2include.py') diff --git a/lv2include/lv2include.py b/lv2include/lv2include.py index 8786411..f4b9b3c 100755 --- a/lv2include/lv2include.py +++ b/lv2include/lv2include.py @@ -34,8 +34,20 @@ import sys import RDF -rdf = RDF.NS('http://www.w3.org/1999/02/22-rdf-syntax-ns#') -lv2 = RDF.NS('http://lv2plug.in/ns/lv2core#') +def rdf_load(uri): + 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_namespace(uri): + return RDF.NS(uri) + +rdf = rdf_namespace('http://www.w3.org/1999/02/22-rdf-syntax-ns#') +lv2 = rdf_namespace('http://lv2plug.in/ns/lv2core#') def lv2_path(): "Return the LV2 search path (LV2_PATH in the environment, or a default)." @@ -81,12 +93,10 @@ def build_tree(search_path, outdir): the extension URIs.""" for bundle in __bundles(search_path): # Load manifest into model - manifest = RDF.Model() - parser = RDF.Parser(name="guess") - parser.parse_into_model(manifest, 'file://' + os.path.join(bundle, 'manifest.ttl')) + manifest = rdf_load('file://' + os.path.join(bundle, 'manifest.ttl')) # Query extension URI - results = manifest.find_statements(RDF.Statement(None, rdf.type, lv2.Specification)) + results = rdf_find(manifest, None, rdf.type, lv2.Specification) for r in results: ext_uri = str(r.subject.uri) ext_scheme = ext_uri[0:ext_uri.find(':')] -- cgit v1.2.1