From df9e0af193e851288ea02ff4189ce3e6640fee48 Mon Sep 17 00:00:00 2001 From: Fabio Erculiani Date: Thu, 11 Nov 2010 19:18:08 +0100 Subject: [PATCH] [molecule] add support for MOLECULE_TMPDIR environment variable (defaulting to /var/tmp), so that user can override it --- molecule/settings.py | 3 +++ molecule/specs/plugins/image_plugin.py | 2 +- molecule/utils.py | 8 +++++--- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/molecule/settings.py b/molecule/settings.py index a00a901..f99eccd 100644 --- a/molecule/settings.py +++ b/molecule/settings.py @@ -32,9 +32,11 @@ class Constants(dict): def load(self): ETC_DIR = '/etc' CONFIG_FILE_NAME = 'molecule.conf' + TMP_DIR = os.getenv("MOLECULE_TMPDIR", "/var/tmp") mysettings = { 'config_file': os.path.join(ETC_DIR, CONFIG_FILE_NAME), + 'tmp_dir': TMP_DIR, } self.clear() @@ -52,6 +54,7 @@ class Configuration(dict): mysettings = {} settings = { 'version': VERSION, + 'tmp_dir': self.Constants['tmp_dir'], 'chroot_compressor': "/usr/bin/mksquashfs", 'iso_builder': "/usr/bin/mkisofs", 'mirror_syncer': "/usr/bin/rsync", diff --git a/molecule/specs/plugins/image_plugin.py b/molecule/specs/plugins/image_plugin.py index 2c26b6d..fa5ff34 100644 --- a/molecule/specs/plugins/image_plugin.py +++ b/molecule/specs/plugins/image_plugin.py @@ -70,7 +70,7 @@ class ImageHandler(GenericExecutionStep, BuiltinHandlerMixin): return sts try: self._tmp_loop_device_fd, self.tmp_loop_device_file = \ - tempfile.mkstemp(prefix = "molecule", dir = "/var/tmp") + tempfile.mkstemp(prefix = "molecule", dir = self._config['tmp_dir']) except (OSError, IOError,) as err: self._output.output("[%s|%s] %s: %s" % ( blue("ImageHandler"), darkred(self.spec_name), diff --git a/molecule/utils.py b/molecule/utils.py index 1b8a933..c45eb92 100644 --- a/molecule/utils.py +++ b/molecule/utils.py @@ -126,10 +126,12 @@ def empty_dir(dest_dir): def mkdtemp(suffix=''): """ - Generate a reliable temporary directory inside /var/tmp starting with - "molecule". + Generate a reliable temporary directory inside MOLECULE_TMPDIR + env var (/var/tmp) starting with "molecule". """ - return tempfile.mkdtemp(prefix = "molecule", dir = "/var/tmp", + import molecule.settings + tmp_dir = molecule.settings.Configuration()['tmp_dir'] + return tempfile.mkdtemp(prefix = "molecule", dir = tmp_dir, suffix = suffix) # using subprocess.call to not care about wildcards