diff options
author | Tiago Gomes <tiago.gomes@codethink.co.uk> | 2013-06-05 13:31:13 +0000 |
---|---|---|
committer | Tiago Gomes <tiago.gomes@codethink.co.uk> | 2013-06-05 16:59:29 +0000 |
commit | b4a633a5229b6c3380cde0cc67da037ea8091008 (patch) | |
tree | c5f61a51eedbf5600ac9bcaa0249ce422ead7e6e /morphlib | |
parent | 86cbc1bc8ef84dc9496d7723a15dec9b43eacb73 (diff) | |
download | morph-b4a633a5229b6c3380cde0cc67da037ea8091008.tar.gz |
Change the structure of the temporary directory used by morph
Now, inside the temporary directory we will have the following
subdirectories: chunks, staging, failed and deployments. The failed
directory will contain the staging areas of failed builds.
Diffstat (limited to 'morphlib')
-rw-r--r-- | morphlib/app.py | 21 | ||||
-rw-r--r-- | morphlib/buildcommand.py | 5 | ||||
-rw-r--r-- | morphlib/builder2.py | 4 | ||||
-rw-r--r-- | morphlib/plugins/deploy_plugin.py | 7 | ||||
-rw-r--r-- | morphlib/stagingarea.py | 6 |
5 files changed, 31 insertions, 12 deletions
diff --git a/morphlib/app.py b/morphlib/app.py index 267dab1b..35739a59 100644 --- a/morphlib/app.py +++ b/morphlib/app.py @@ -128,7 +128,7 @@ class Morph(cliapp.Application): 'this setting can point at a directory in ' 'NFS)', metavar='DIR', - default=os.environ.get('TMPDIR'), + default=None, group=group_build) # These cannot be removed just yet because existing morph.conf files @@ -183,10 +183,21 @@ class Morph(cliapp.Application): self.settings['compiler-cache-dir'] = os.path.join( self.settings['cachedir'], 'ccache') if self.settings['tempdir'] is None: - if 'TMPDIR' in os.environ: - self.settings['tempdir'] = os.environ['TMPDIR'] - else: - self.settings['tempdir'] = '/tmp' + tmpdir_base = os.environ.get('TMPDIR', '/tmp') + tmpdir = os.path.join(tmpdir_base, 'morph_tmp') + self.settings['tempdir'] = tmpdir + + def create_dir_if_not_exists(dir): + if not os.path.exists(dir): + os.makedirs(dir) + + tmpdir = self.settings['tempdir'] + create_dir_if_not_exists(tmpdir) + create_dir_if_not_exists(os.path.join(tmpdir, 'chunks')) + create_dir_if_not_exists(os.path.join(tmpdir, 'staging')) + create_dir_if_not_exists(os.path.join(tmpdir, 'failed')) + create_dir_if_not_exists(os.path.join(tmpdir, 'deployments')) + if 'MORPH_DUMP_PROCESSED_CONFIG' in os.environ: self.settings.dump_config(sys.stdout) sys.exit(0) diff --git a/morphlib/buildcommand.py b/morphlib/buildcommand.py index 5be216e1..ac230970 100644 --- a/morphlib/buildcommand.py +++ b/morphlib/buildcommand.py @@ -333,9 +333,10 @@ class BuildCommand(object): '''Create the staging area for building a single artifact.''' self.app.status(msg='Creating staging area') - staging_dir = tempfile.mkdtemp(dir=self.app.settings['tempdir']) + staging_dir = os.path.join(self.app.settings['tempdir'], 'staging') + tmp_staging_area_dir = tempfile.mkdtemp(dir=staging_dir) staging_area = morphlib.stagingarea.StagingArea( - self.app, staging_dir, build_env, use_chroot, extra_env, + self.app, tmp_staging_area_dir, build_env, use_chroot, extra_env, extra_path) return staging_area diff --git a/morphlib/builder2.py b/morphlib/builder2.py index 59c62222..459094f4 100644 --- a/morphlib/builder2.py +++ b/morphlib/builder2.py @@ -314,6 +314,10 @@ class ChunkBuilder(BuilderBase): for line in f: logging.error('OUTPUT FROM FAILED BUILD: %s' % line.rstrip('\n')) + src_dir = self.staging_area.dirname + dest_dir = os.path.join(self.app.settings['tempdir'], + 'failed') + cliapp.runcmd(['mv', src_dir, dest_dir]) raise self.staging_area.chroot_close() built_artifacts = self.assemble_chunk_artifacts(destdir) diff --git a/morphlib/plugins/deploy_plugin.py b/morphlib/plugins/deploy_plugin.py index 7a6f2b92..19c57640 100644 --- a/morphlib/plugins/deploy_plugin.py +++ b/morphlib/plugins/deploy_plugin.py @@ -128,7 +128,9 @@ class DeployPlugin(cliapp.Plugin): # Unpack the artifact (tarball) to a temporary directory. self.app.status(msg='Unpacking system for configuration') - system_tree = tempfile.mkdtemp(dir=self.app.settings['tempdir']) + deployment_dir = os.path.join(self.app.settings['tempdir'], + 'deployments') + system_tree = tempfile.mkdtemp(dir=deployment_dir) if build_command.lac.has(artifact): f = build_command.lac.get(artifact) @@ -157,7 +159,8 @@ class DeployPlugin(cliapp.Plugin): if 'TMPDIR' not in env: # morphlib.app already took care of ensuring the tempdir setting # is good, so use it if we don't have one already set. - env['TMPDIR'] = self.app.settings['tempdir'] + env['TMPDIR'] = os.path.join(self.app.settings['tempdir'], + 'deployments') # Run configuration extensions. self.app.status(msg='Configure system') diff --git a/morphlib/stagingarea.py b/morphlib/stagingarea.py index 8150ba42..8e92e039 100644 --- a/morphlib/stagingarea.py +++ b/morphlib/stagingarea.py @@ -44,7 +44,7 @@ class StagingArea(object): self.dirname = dirname self.builddirname = None self.destdirname = None - self.mounted = None + self.mounted = [] self._bind_readonly_mount = None self.use_chroot = use_chroot @@ -61,7 +61,7 @@ class StagingArea(object): # Wrapper to be overridden by unit tests. def _mkdir(self, dirname): # pragma: no cover - os.mkdir(dirname) + os.makedirs(dirname) def _dir_for_source(self, source, suffix): dirname = os.path.join(self.dirname, @@ -160,6 +160,7 @@ class StagingArea(object): unpacked_artifact = os.path.join( self._app.settings['tempdir'], + 'chunks', os.path.basename(handle.name) + '.d') if not os.path.exists(unpacked_artifact): self._mkdir(unpacked_artifact) @@ -220,7 +221,6 @@ class StagingArea(object): return ccache_destdir def do_mounts(self, setup_mounts): # pragma: no cover - self.mounted = [] if not setup_mounts: return for mount_point, mount_type, source in self.to_mount: |