diff options
author | Tiago Gomes <tiago.gomes@codethink.co.uk> | 2013-06-05 18:38:31 +0100 |
---|---|---|
committer | Tiago Gomes <tiago.gomes@codethink.co.uk> | 2013-06-05 18:38:31 +0100 |
commit | 710af7e4bc5e3654221ce23d5b3ccbafbd0eae0c (patch) | |
tree | 8ef2cd494d0ca0b7bba7daec00171dea7821e756 | |
parent | 7e74c354db185291ae9fecb8fef2d7ebb172c3d1 (diff) | |
parent | b4a633a5229b6c3380cde0cc67da037ea8091008 (diff) | |
download | morph-710af7e4bc5e3654221ce23d5b3ccbafbd0eae0c.tar.gz |
Merge branch 'baserock/tiagogomes/tmpdir' of git://git.baserock.org/baserock/baserock/morph
I had fixed an conflict and change to use morph_tmp instead of
morph as default temp dir.
Reviewed by Lars Wirzenius
Conflicts:
morphlib/app.py
-rw-r--r-- | morphlib/app.py | 28 | ||||
-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, 33 insertions, 17 deletions
diff --git a/morphlib/app.py b/morphlib/app.py index a278b529..b4d316e8 100644 --- a/morphlib/app.py +++ b/morphlib/app.py @@ -121,7 +121,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_storage) self.settings.string(['cachedir'], 'cache git repositories and build results in DIR', @@ -215,19 +215,27 @@ 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')) + + create_dir_if_not_exists(self.settings['cachedir']) + if 'MORPH_DUMP_PROCESSED_CONFIG' in os.environ: self.settings.dump_config(sys.stdout) sys.exit(0) - for dirconfig in ("cachedir", "tempdir"): - path = self.settings[dirconfig] - if not os.path.exists(path): - os.makedirs(path) - cliapp.Application.process_args(self, args) def setup_plugin_manager(self): 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 574a5e04..6b3b128f 100644 --- a/morphlib/plugins/deploy_plugin.py +++ b/morphlib/plugins/deploy_plugin.py @@ -137,7 +137,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) @@ -166,7 +168,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: |