From 32ae4ee71814d08837f6a63bf2f25876e28bba14 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/utils.py | 8 +++++--- 2 files changed, 8 insertions(+), 3 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/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