diff options
author | Adam Coldrick <adam.coldrick@codethink.co.uk> | 2015-04-15 12:17:16 +0000 |
---|---|---|
committer | Morph (on behalf of Adam Coldrick) <adam.coldrick@codethink.co.uk> | 2015-04-15 12:17:16 +0000 |
commit | 85995d210162d1432800acf357f8162b77f5b47e (patch) | |
tree | 256ba048782865a8d9b52e497ff0ea5f694d652b /morphlib/builder.py | |
parent | 3167ced4844c9602e88289607d1c2cc2ecbd5d95 (diff) | |
download | morph-baserock/6453f312359f4317803ef7f14b58d21f/d675b946df4f456693ed211dcd2ec95e.tar.gz |
Morph build c3874f415dc6448ca28d9a01edab0948baserock/6453f312359f4317803ef7f14b58d21f/d675b946df4f456693ed211dcd2ec95e
System branch: master
Diffstat (limited to 'morphlib/builder.py')
-rw-r--r-- | morphlib/builder.py | 34 |
1 files changed, 23 insertions, 11 deletions
diff --git a/morphlib/builder.py b/morphlib/builder.py index e5b891b2..b0c95bb3 100644 --- a/morphlib/builder.py +++ b/morphlib/builder.py @@ -558,16 +558,32 @@ class SystemBuilder(BuilderBase): # pragma: no cover self.save_build_times() return self.source.artifacts.itervalues() + def load_stratum(self, stratum_artifact): + '''Load a stratum from the local artifact cache. + + Returns a list of ArtifactCacheReference instances for the chunks + contained in the stratum. + + ''' + cache = self.local_artifact_cache + with open(cache.get(stratum_artifact), 'r') as stratum_file: + try: + artifact_list = json.load(stratum_file, + encoding='unicode-escape') + except ValueError as e: + raise cliapp.AppException( + 'Corruption detected: %s while loading %s' % + (e, cache.artifact_filename(stratum_artifact))) + return [ArtifactCacheReference(a) for a in artifact_list] + def unpack_one_stratum(self, stratum_artifact, target): '''Unpack a single stratum into a target directory''' cache = self.local_artifact_cache - with open(cache.get(stratum_artifact), 'r') as stratum_file: - artifact_list = json.load(stratum_file, encoding='unicode-escape') - for chunk in (ArtifactCacheReference(a) for a in artifact_list): - self.app.status(msg='Checkout chunk %(basename)s', - basename=chunk.basename(), chatty=True) - cache.get(chunk, target) + for chunk in self.load_stratum(stratum_artifact): + self.app.status(msg='Checkout chunk %(basename)s', + basename=chunk.basename(), chatty=True) + cache.get(chunk, target) target_metadata = os.path.join( target, 'baserock', '%s.meta' % stratum_artifact.name) @@ -590,11 +606,7 @@ class SystemBuilder(BuilderBase): # pragma: no cover # download the chunk artifacts if necessary for stratum_artifact in self.source.dependencies: - stratum_path = self.local_artifact_cache.get( - stratum_artifact) - with open(stratum_path, 'r') as stratum: - chunks = [ArtifactCacheReference(c) - for c in json.load(stratum)] + chunks = self.load_stratum(stratum_artifact) download_depends(chunks, self.local_artifact_cache, self.remote_artifact_cache) |