diff options
author | Jannis Pohlmann <jannis.pohlmann@codethink.co.uk> | 2012-05-09 13:49:14 +0000 |
---|---|---|
committer | Jannis Pohlmann <jannis.pohlmann@codethink.co.uk> | 2012-05-09 13:57:04 +0000 |
commit | f521d1b84a10ba801a1627fa3ff13d546e38ec2b (patch) | |
tree | aa0a6e138bd3d60e937722259f6e039f57ba10bb /morphlib/builder2.py | |
parent | 59ff4918d6e48db2ffe588b9752aaf26f4bb0ca8 (diff) | |
download | morph-f521d1b84a10ba801a1627fa3ff13d546e38ec2b.tar.gz |
Create system images directly in the artifact cache using SaveFile.
This avoids having to copy the generated image files to the cache later,
which can take (almost) forever.
Diffstat (limited to 'morphlib/builder2.py')
-rw-r--r-- | morphlib/builder2.py | 21 |
1 files changed, 5 insertions, 16 deletions
diff --git a/morphlib/builder2.py b/morphlib/builder2.py index 50d2fc35..65bd143c 100644 --- a/morphlib/builder2.py +++ b/morphlib/builder2.py @@ -355,8 +355,9 @@ class SystemBuilder(BuilderBase): # pragma: no cover self.ex = morphlib.execute.Execute(self.staging_area.tempdir, logging.debug) - image_name = os.path.join(self.staging_area.tempdir, - '%s.img' % self.artifact.name) + handle = self.local_artifact_cache.put(self.artifact) + image_name = handle._savefile_tempname + self._create_image(image_name) self._partition_image(image_name) self._install_mbr(image_name) @@ -378,15 +379,16 @@ class SystemBuilder(BuilderBase): # pragma: no cover self._install_boot_files(factory_run_path, mount_point) self._install_extlinux(mount_point) self._unmount(mount_point) + handle.close() except BaseException, e: logging.error('Got error while system image building, ' 'unmounting and device unmapping') self._unmount(mount_point) self._undo_device_mapping(image_name) + handle.abort() raise self._undo_device_mapping(image_name) - self._move_image_to_cache(image_name) self.save_build_times() def _create_image(self, image_name): @@ -504,19 +506,6 @@ class SystemBuilder(BuilderBase): # pragma: no cover with self.build_watch('undo-device-mapper'): morphlib.fsutils.undo_device_mapping(self.ex, image_name) - def _move_image_to_cache(self, image_name): - logging.debug('Moving image to cache: %s' % image_name) - # FIXME: Need to create file directly in cache to avoid costly - # copying here. - with self.build_watch('cache-image'): - with self.local_artifact_cache.put(self.artifact) as outf: - with open(image_name) as inf: - while True: - data = inf.read(1024**2) - if not data: - break - outf.write(data) - class Builder(object): # pragma: no cover |