From 5aad0f5a8249f1f20f802aa094343fb9df1a1656 Mon Sep 17 00:00:00 2001 From: Richard Maw Date: Thu, 2 Oct 2014 11:26:01 +0000 Subject: 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). --- distbuild/serialise.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'distbuild') 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'] -- cgit v1.2.1