summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Thursfield <sam.thursfield@codethink.co.uk>2015-07-07 10:58:16 +0100
committerSam Thursfield <sam.thursfield@codethink.co.uk>2015-07-07 10:58:16 +0100
commit1f313539fc0af37e565607dbd57895c3e3c8fbf8 (patch)
tree00e797f601ee052d8c6aa1f28d4b1777e113fc4d
parent58369b5f89c57da52a1a52e445e86f2c4929b1d3 (diff)
downloaddefinitions-1f313539fc0af37e565607dbd57895c3e3c8fbf8.tar.gz
schema: Correctly set rdf:type again
Since commit c56805de1bf679384345e8516d8c89b41a7e74ea (stop using SuRF) the load_all_morphologies() function was not setting rdf:type for any of the entities, which is totally wrong. Change-Id: Idedb161857e29598418b78aca2a834b2b6ccf0a6
-rw-r--r--schema/parse.py34
1 files changed, 26 insertions, 8 deletions
diff --git a/schema/parse.py b/schema/parse.py
index 8a79e986..b9c0fec8 100644
--- a/schema/parse.py
+++ b/schema/parse.py
@@ -37,6 +37,7 @@ import warnings
BASEROCK = rdflib.Namespace('http://baserock.org/definitions/example-schema#')
DUBLIN_CORE = rdflib.Namespace('http://purl.org/dc/terms/')
+RDF = rdflib.RDF
def parse_morph_file(path):
@@ -106,6 +107,18 @@ class DefinitionsNamespace(rdflib.Namespace):
return cluster_uriref + '/' + label
+def new_resource(graph, uriref, rdf_type):
+ '''Create a new resource, stored in 'graph' and identified by 'uriref'.
+
+ Returns an rdflib.resource.Resource instance which can be used to query
+ and update the information about the resource that is stored in 'graph'.
+
+ '''
+ entity = rdflib.resource.Resource(graph, uriref)
+ entity.set(RDF.type, rdf_type)
+ return entity
+
+
def ordered(graph, value_list, node=None):
'''Create an ordered RDF collection from a list of values.
@@ -146,7 +159,7 @@ def load_all_morphologies(path='.'):
if contents['kind'] == 'chunk':
chunk_uriref = ns.chunk(contents['name'])
- entity = chunk = rdflib.resource.Resource(graph, chunk_uriref)
+ entity = chunk = new_resource(graph, chunk_uriref, BASEROCK.Chunk)
if 'pre-configure-commands' in contents:
chunk.set(BASEROCK.preConfigureCommands,
@@ -178,7 +191,8 @@ def load_all_morphologies(path='.'):
elif contents['kind'] == 'stratum':
stratum_uriref = ns.stratum(contents['name'])
- entity = stratum = rdflib.resource.Resource(graph, stratum_uriref)
+ entity = stratum = new_resource(
+ graph, stratum_uriref, BASEROCK.Stratum)
for entry in contents.get('build-depends', []):
build_dep_file = os.path.join(toplevel_path, entry['morph'])
@@ -189,7 +203,8 @@ def load_all_morphologies(path='.'):
for entry in contents.get('products', []):
artifact_uri = ns.stratum_artifact(
stratum_uriref, entry['artifact'])
- artifact = rdflib.resource.Resource(graph, artifact_uri)
+ artifact = new_resource(
+ graph, artifact_uri, BASEROCK.StratumArtifact)
# FIXME: order probably lost here
if 'includes' in entry:
artifact.set(BASEROCK.includes,
@@ -210,7 +225,8 @@ def load_all_morphologies(path='.'):
chunk_ref_uriref = ns.chunk_reference(
stratum_uriref, chunk_name)
- chunk_ref = rdflib.resource.Resource(graph, chunk_ref_uriref)
+ chunk_ref = new_resource(
+ graph, chunk_ref_uriref, BASEROCK.ChunkReference)
chunk_uriref = ns.chunk(chunk_name)
chunk_ref.set(BASEROCK.refersToChunk, chunk_uriref)
@@ -235,7 +251,8 @@ def load_all_morphologies(path='.'):
elif contents['kind'] == 'system':
system_uriref = ns.system(contents['name'])
- entity = system = rdflib.resource.Resource(graph, system_uriref)
+ entity = system = new_resource(
+ graph, system_uriref, BASEROCK.System)
system.set(BASEROCK.arch, rdflib.Literal(contents['arch']))
@@ -260,7 +277,8 @@ def load_all_morphologies(path='.'):
elif contents['kind'] == 'cluster':
cluster_uriref = ns.cluster(contents['name'])
- entity = cluster = rdflib.resource.Resource(graph, cluster_uriref)
+ entity = cluster = new_resource(
+ graph, cluster_uriref, BASEROCK.Cluster)
for entry in contents.get('systems', []):
system_morph_file = os.path.join(toplevel_path, entry['morph'])
@@ -271,8 +289,8 @@ def load_all_morphologies(path='.'):
for label, details in entry['deploy'].items():
deployment_uriref = ns.system_deployment(
cluster_uriref, label)
- deployment = rdflib.resource.Resource(
- graph, deployment_uriref)
+ deployment = new_resource(
+ graph, deployment_uriref, BASEROCK.SystemDeployment)
deployment.set(BASEROCK.deploysSystem, system_uriref)
deployment.set(BASEROCK.hasLabel, rdflib.Literal(label))