summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Thursfield <sam.thursfield@codethink.co.uk>2015-07-06 18:22:44 +0100
committerSam Thursfield <sam.thursfield@codethink.co.uk>2015-07-06 18:22:44 +0100
commit503f3bc78b5bed94d6519a7a840b4e75ce2322fd (patch)
tree538638811082f66bc8112e3b106984b1439fb7a7
parenta9cc468044c07f14154b4bbcbc2785f4a8eb7977 (diff)
downloaddefinitions-503f3bc78b5bed94d6519a7a840b4e75ce2322fd.tar.gz
schema: Attempt to ensure chunk commands are ordered properly
This isn't tested yet fully because the browser example app has started ignoring all of the data. Change-Id: I91ca6b519f6feacb9e6e5269c577858d285009aa
-rw-r--r--schema/parse.py56
1 files changed, 35 insertions, 21 deletions
diff --git a/schema/parse.py b/schema/parse.py
index 1ee1b367..8a79e986 100644
--- a/schema/parse.py
+++ b/schema/parse.py
@@ -28,6 +28,7 @@ The current version of the Baserock Definitions format is defined at:
import rdflib
+import rdflib.collection
import yaml
import os
@@ -67,8 +68,6 @@ def get_name_from_morph_file(path):
return contents['name']
-# FIXME: can you use assignment instead of Resource.set ?
-
class DefinitionsNamespace(rdflib.Namespace):
'''Helpers to construct URIs for Baserock entities.
@@ -107,6 +106,21 @@ class DefinitionsNamespace(rdflib.Namespace):
return cluster_uriref + '/' + label
+def ordered(graph, value_list, node=None):
+ '''Create an ordered RDF collection from a list of values.
+
+ To define an ordered list in RDF, you need an identifier for the list
+ itself. By default this function will create a 'blank node', which will end
+ up with a random unique URI when serialised. To make serialised data more
+ readable you can create your own rdflib.URIRef term to identify the list.
+
+ '''
+ node = node or rdflib.BNode()
+ collection = rdflib.collection.Collection(
+ graph, node, [rdflib.Literal(v) for v in value_list])
+ return node
+
+
def load_all_morphologies(path='.'):
'''Load Baserock Definitions serialisation format V5 as an RDFLib 'graph'.
@@ -117,6 +131,7 @@ def load_all_morphologies(path='.'):
toplevel_path = path
graph = rdflib.Graph()
+
def load_morph(toplevel_path, filename):
try:
contents = parse_morph_file(filename)
@@ -133,34 +148,33 @@ def load_all_morphologies(path='.'):
chunk_uriref = ns.chunk(contents['name'])
entity = chunk = rdflib.resource.Resource(graph, chunk_uriref)
- # FIXME: order is lost here !!!!!
if 'pre-configure-commands' in contents:
- chunk.add(BASEROCK.preConfigureCommands,
- rdflib.Literal(contents['pre-configure-commands']))
+ chunk.set(BASEROCK.preConfigureCommands,
+ ordered(graph, contents['pre-configure-commands']))
if 'configure-commands' in contents:
- chunk.add(BASEROCK.configureCommands,
- rdflib.Literal(contents['configure-commands']))
+ chunk.set(BASEROCK.configureCommands,
+ ordered(graph, contents['configure-commands']))
if 'post-configure-commands' in contents:
- chunk.add(BASEROCK.postConfigureCommands,
- rdflib.Literal(contents['post-configure-commands']))
+ chunk.set(BASEROCK.postConfigureCommands,
+ ordered(graph, contents['post-configure-commands']))
if 'pre-build-commands' in contents:
- chunk.add(BASEROCK.preBuildCommands,
- rdflib.Literal(contents['pre-build-commands']))
+ chunk.set(BASEROCK.preBuildCommands,
+ ordered(graph, contents['pre-build-commands']))
if 'build-commands' in contents:
- chunk.add(BASEROCK.buildCommands,
- rdflib.Literal(contents['build-commands']))
+ chunk.set(BASEROCK.buildCommands,
+ ordered(graph, contents['build-commands']))
if 'post-build-commands' in contents:
- chunk.add(BASEROCK.postBuildCommands,
- rdflib.Literal(contents['post-build-commands']))
+ chunk.set(BASEROCK.postBuildCommands,
+ ordered(graph, contents['post-build-commands']))
if 'pre-install-commands' in contents:
- chunk.add(BASEROCK.preInstallCommands,
- rdflib.Literal(contents['pre-install-commands']))
+ chunk.set(BASEROCK.preInstallCommands,
+ ordered(graph, contents['pre-install-commands']))
if 'install-commands' in contents:
- chunk.add(BASEROCK.installCommands,
- rdflib.Literal(contents['install-commands']))
+ chunk.set(BASEROCK.installCommands,
+ ordered(graph, contents['install-commands']))
if 'post-install-commands' in contents:
- chunk.add(BASEROCK.postInstallCommands,
- rdflib.Literal(contents['post-install-commands']))
+ chunk.set(BASEROCK.postInstallCommands,
+ ordered(graph, contents['post-install-commands']))
elif contents['kind'] == 'stratum':
stratum_uriref = ns.stratum(contents['name'])