diff options
author | Sam Thursfield <sam.thursfield@codethink.co.uk> | 2015-07-02 13:27:08 +0100 |
---|---|---|
committer | Sam Thursfield <sam.thursfield@codethink.co.uk> | 2015-07-02 13:27:08 +0100 |
commit | 5174d4dd33ef2670cb294883d55cbe6f0d977324 (patch) | |
tree | a5e863a8363c9ae4ba9f62451c3d49dbf49229b2 | |
parent | 15905d728a0ee1b4df3f2e29fb9987cc2ae842bd (diff) | |
download | definitions-5174d4dd33ef2670cb294883d55cbe6f0d977324.tar.gz |
schema: Link clusters to systems properly
Previously this was a FIXME placeholder.
Change-Id: I1979dde0e63abb0d45aa16126589cd81d4410c73
-rw-r--r-- | schema/parse.py | 38 |
1 files changed, 26 insertions, 12 deletions
diff --git a/schema/parse.py b/schema/parse.py index 079b3b2b..02f022fe 100644 --- a/schema/parse.py +++ b/schema/parse.py @@ -15,7 +15,22 @@ surf.ns.register(baserock='http://baserock.org/definitions/example-schema#') surf.ns.register(dc='http://purl.org/dc/terms/') -def load_all_morphologies(session, store): +def parse_morph_file(path): + with open(path) as f: + text = f.read() + contents = yaml.safe_load(text) + morph_type = contents['kind'] + assert 'name' in contents + assert contents['kind'] in ['cluster', 'system', 'stratum', 'chunk'] + return contents + + +def get_name_from_morph_file(path): + contents = parse_morph_file(path) + return contents['name'] + + +def load_all_morphologies(session, store, path='.'): Chunk = session.get_class(surf.ns.BASEROCK.Chunk) ChunkReference = session.get_class(surf.ns.BASEROCK.ChunkReference) Stratum = session.get_class(surf.ns.BASEROCK.Stratum) @@ -24,16 +39,13 @@ def load_all_morphologies(session, store): SystemDeployment = session.get_class(surf.ns.BASEROCK.SystemDeployment) Cluster = session.get_class(surf.ns.BASEROCK.Cluster) - def load_morph(path): + toplevel_path = path + + def load_morph(toplevel_path, filename): try: - with open(path) as f: - text = f.read() - contents = yaml.safe_load(text) - morph_type = contents['kind'] - assert 'name' in contents - assert contents['kind'] in ['cluster', 'system', 'stratum', 'chunk'] + contents = parse_morph_file(filename) except Exception as e: - warnings.warn("Problem loading %s: %s" % (path, e)) + warnings.warn("Problem loading %s: %s" % (filename, e)) # FIXME: base_uri = 'http://example.com/' @@ -148,7 +160,9 @@ def load_all_morphologies(session, store): for entry in contents.get('systems', []): # FIXME: can't get the URI from the 'morph' entry... need to load # the actual .morph file and get the name from there. - system_uri = 'http://FIXME' + system_morph_file = os.path.join(toplevel_path, entry['morph']) + system_name = get_name_from_morph_file(system_morph_file) + system_uri = base_uri + 'systems/' + system_name # FIXME: ignores deploy-defaults at present for label, details in entry['deploy'].items(): @@ -183,12 +197,12 @@ def load_all_morphologies(session, store): # and dump that into a property. print 'Parsing .morph files...' - for dirname, dirnames, filenames in os.walk('..'): + for dirname, dirnames, filenames in os.walk(toplevel_path): if '.git' in dirnames: dirnames.remove('.git') for filename in sorted(filenames): if filename.endswith('.morph'): - load_morph(os.path.join(dirname, filename)) + load_morph(toplevel_path, os.path.join(dirname, filename)) print 'Committing to database...' try: |