summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Maw <richard.maw@codethink.co.uk>2014-10-02 11:26:01 +0000
committerRichard Maw <richard.maw@gmail.com>2014-10-08 12:14:03 +0000
commit5aad0f5a8249f1f20f802aa094343fb9df1a1656 (patch)
tree8e03346e0596cd2fa0e9202aadf38ce05d07f14f
parent3f8ea43f0af9fd2c8a2cf2aa21b9963fa70043d6 (diff)
downloadmorph-5aad0f5a8249f1f20f802aa094343fb9df1a1656.tar.gz
Allow distbuilding morphologies with binary data embedded
The horrible json.dumped, yaml dump is because we need it to be both binary safe (which yaml gives us) and one line per message (which json gives us).
-rw-r--r--distbuild/serialise.py19
1 files changed, 10 insertions, 9 deletions
diff --git a/distbuild/serialise.py b/distbuild/serialise.py
index 2b39000e..a27a526b 100644
--- a/distbuild/serialise.py
+++ b/distbuild/serialise.py
@@ -17,6 +17,7 @@
import json
+import yaml
import morphlib
import logging
@@ -39,16 +40,14 @@ def serialise_artifact(artifact):
'original_ref': source.original_ref,
'sha1': source.sha1,
'tree': source.tree,
- 'morphology': str(id(source.morphology)),
+ 'morphology': id(source.morphology),
'filename': source.filename,
- # dict keys are converted to strings by json
- # so we encode the artifact ids as strings
- 'artifact_ids': [str(id(artifact)) for (_, artifact)
+ 'artifact_ids': [id(artifact) for (_, artifact)
in source.artifacts.iteritems()],
'cache_id': source.cache_id,
'cache_key': source.cache_key,
- 'dependencies': [str(id(d))
+ 'dependencies': [id(d)
for d in source.dependencies],
}
@@ -85,15 +84,17 @@ def serialise_artifact(artifact):
if id(a) not in encoded_artifacts: # pragma: no cover
encoded_artifacts[id(a)] = encode_artifact(a)
- return json.dumps({'sources': encoded_sources,
+ content = {
+ 'sources': encoded_sources,
'artifacts': encoded_artifacts,
'morphologies': encoded_morphologies,
- 'root_artifact': str(id(artifact)),
+ 'root_artifact': id(artifact),
'default_split_rules': {
'chunk': morphlib.artifactsplitrule.DEFAULT_CHUNK_RULES,
'stratum': morphlib.artifactsplitrule.DEFAULT_STRATUM_RULES,
},
- })
+ }
+ return json.dumps(yaml.dump(content))
def deserialise_artifact(encoded):
@@ -148,7 +149,7 @@ def deserialise_artifact(encoded):
return artifact
- le_dicts = json.loads(encoded)
+ le_dicts = yaml.load(json.loads(encoded))
artifacts_dict = le_dicts['artifacts']
sources_dict = le_dicts['sources']
morphologies_dict = le_dicts['morphologies']