diff options
author | Richard Maw <richard.maw@codethink.co.uk> | 2013-06-06 11:42:20 +0100 |
---|---|---|
committer | Richard Maw <richard.maw@codethink.co.uk> | 2013-06-06 11:42:20 +0100 |
commit | 67e9a9305cfe8e916a468fc21a7383a129c0a23e (patch) | |
tree | ddc663b6a8bcedde7a411cb3ef78043573c5b39a | |
parent | 710af7e4bc5e3654221ce23d5b3ccbafbd0eae0c (diff) | |
parent | c8185c29c3d5d74a1709a440fa6a8bdbf9600cda (diff) | |
download | morph-67e9a9305cfe8e916a468fc21a7383a129c0a23e.tar.gz |
Merge branch 'baserock/richardmaw/suggested-cleanups-for-tmpdir' of git://git.baserock.org/baserock/baserock/morph
Reviewed-by: Tiago Gomes
-rw-r--r-- | morphlib/app.py | 22 | ||||
-rw-r--r-- | morphlib/buildcommand.py | 6 | ||||
-rw-r--r-- | morphlib/builder2.py | 2 | ||||
-rw-r--r-- | morphlib/plugins/deploy_plugin.py | 5 |
4 files changed, 15 insertions, 20 deletions
diff --git a/morphlib/app.py b/morphlib/app.py index b4d316e8..fcf54118 100644 --- a/morphlib/app.py +++ b/morphlib/app.py @@ -219,23 +219,19 @@ class Morph(cliapp.Application): 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) + tmpdir = self.settings['tempdir'] + for required_dir in (os.path.join(tmpdir, 'chunks'), + os.path.join(tmpdir, 'staging'), + os.path.join(tmpdir, 'failed'), + os.path.join(tmpdir, 'deployments'), + self.settings['cachedir']): + if not os.path.exists(required_dir): + os.makedirs(required_dir) + cliapp.Application.process_args(self, args) def setup_plugin_manager(self): diff --git a/morphlib/buildcommand.py b/morphlib/buildcommand.py index ac230970..97c5ff86 100644 --- a/morphlib/buildcommand.py +++ b/morphlib/buildcommand.py @@ -333,10 +333,10 @@ class BuildCommand(object): '''Create the staging area for building a single artifact.''' self.app.status(msg='Creating staging area') - staging_dir = os.path.join(self.app.settings['tempdir'], 'staging') - tmp_staging_area_dir = tempfile.mkdtemp(dir=staging_dir) + staging_dir = tempfile.mkdtemp( + dir=os.path.join(self.app.settings['tempdir'], 'staging')) staging_area = morphlib.stagingarea.StagingArea( - self.app, tmp_staging_area_dir, build_env, use_chroot, extra_env, + self.app, staging_dir, build_env, use_chroot, extra_env, extra_path) return staging_area diff --git a/morphlib/builder2.py b/morphlib/builder2.py index 459094f4..bb791cb4 100644 --- a/morphlib/builder2.py +++ b/morphlib/builder2.py @@ -317,7 +317,7 @@ class ChunkBuilder(BuilderBase): src_dir = self.staging_area.dirname dest_dir = os.path.join(self.app.settings['tempdir'], 'failed') - cliapp.runcmd(['mv', src_dir, dest_dir]) + os.rename(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 6b3b128f..3b2eb388 100644 --- a/morphlib/plugins/deploy_plugin.py +++ b/morphlib/plugins/deploy_plugin.py @@ -137,9 +137,8 @@ class DeployPlugin(cliapp.Plugin): # Unpack the artifact (tarball) to a temporary directory. self.app.status(msg='Unpacking system for configuration') - deployment_dir = os.path.join(self.app.settings['tempdir'], - 'deployments') - system_tree = tempfile.mkdtemp(dir=deployment_dir) + system_tree = tempfile.mkdtemp( + dir=os.path.join(self.app.settings['tempdir'], 'deployments')) if build_command.lac.has(artifact): f = build_command.lac.get(artifact) |