diff options
author | Lars Wirzenius <lars.wirzenius@codethink.co.uk> | 2012-07-26 11:08:55 +0100 |
---|---|---|
committer | Lars Wirzenius <lars.wirzenius@codethink.co.uk> | 2012-07-26 12:01:58 +0100 |
commit | 05fe245d1771ec25d8675b2dd9e4aeee6b22802c (patch) | |
tree | 9c25f99b47865cc192aae94d4c4172dd92bae8ff /morphlib/builder2.py | |
parent | d957103389fca85579b96b3918b68ce65ad02cb2 (diff) | |
download | morph-05fe245d1771ec25d8675b2dd9e4aeee6b22802c.tar.gz |
Move strata unpacking into a base class
Diffstat (limited to 'morphlib/builder2.py')
-rw-r--r-- | morphlib/builder2.py | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/morphlib/builder2.py b/morphlib/builder2.py index 5362dd3c..dd3c530b 100644 --- a/morphlib/builder2.py +++ b/morphlib/builder2.py @@ -476,6 +476,60 @@ class SystemKindBuilder(BuilderBase): # pragma: no cover ''' + def unpack_strata(self, path): + '''Unpack strata into a directory.''' + + self.app.status(msg='Unpacking strata to %(path)s', + path=path, chatty=True) + with self.build_watch('unpack-strata'): + # download the stratum artifacts if necessary + download_depends(self.artifact.dependencies, + self.local_artifact_cache, + self.remote_artifact_cache, + ('meta',)) + + # download the chunk artifacts if necessary + for stratum_artifact in self.artifact.dependencies: + f = self.local_artifact_cache.get(stratum_artifact) + chunks = [ArtifactCacheReference(a) for a in json.load(f)] + download_depends(chunks, + self.local_artifact_cache, + self.remote_artifact_cache) + f.close() + + # check whether the strata overlap + overlaps = get_overlaps(self.artifact, self.artifact.dependencies, + self.local_artifact_cache) + if len(overlaps) > 0: + self.app.status(msg='Overlaps in system artifact ' + '%(artifact_name)s detected', + artifact_name=self.artifact.name, + error=True) + log_overlaps(overlaps) + write_overlap_metadata(self.artifact, overlaps, + self.local_artifact_cache) + + # unpack it from the local artifact cache + for stratum_artifact in self.artifact.dependencies: + f = self.local_artifact_cache.get(stratum_artifact) + for chunk in (ArtifactCacheReference(a) for a in json.load(f)): + self.app.status(msg='Unpacking chunk %(basename)s', + basename=chunk.basename(), chatty=True) + chunk_handle = self.local_artifact_cache.get(chunk) + morphlib.bins.unpack_binary_from_file(chunk_handle, path) + chunk_handle.close() + f.close() + meta = self.local_artifact_cache.get_artifact_metadata( + stratum_artifact, 'meta') + dst = morphlib.savefile.SaveFile( + os.path.join(path, 'baserock', + '%s.meta' % stratum_artifact.name), 'w') + shutil.copyfileobj(meta, dst) + dst.close() + meta.close() + + ldconfig(self.app.runcmd, path) + class SystemKindBuilderFactory(object): # pragma: no cover |