aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChad Austin <chad@imvu.com>2013-01-28 17:58:21 -0800
committerChad Austin <chad@imvu.com>2013-03-04 19:01:45 -0800
commit8dc0e2b7deca6b366066a1b94fe31b7ba4a2b2d0 (patch)
tree92d13f989630a3c458f43dbe2111c0db5b814416
parentc83c53bfe50f8805a0a4ea8bebdac030a2ac53d1 (diff)
Make a Configuration object holding formerly global variables.
-rw-r--r--tools/shared.py32
1 files changed, 18 insertions, 14 deletions
diff --git a/tools/shared.py b/tools/shared.py
index 0580cf03..f46942e6 100644
--- a/tools/shared.py
+++ b/tools/shared.py
@@ -300,20 +300,24 @@ except:
TEMP_DIR = '/tmp'
CANONICAL_TEMP_DIR = os.path.join(TEMP_DIR, 'emscripten_temp')
-EMSCRIPTEN_TEMP_DIR = None
-DEBUG = os.environ.get('EMCC_DEBUG')
-if DEBUG == "0":
- DEBUG = None
-DEBUG_CACHE = DEBUG and "cache" in DEBUG
+class Configuration:
+ def __init__(self, environ=os.environ):
+ self.DEBUG = environ.get('EMCC_DEBUG')
+ self.EMSCRIPTEN_TEMP_DIR = None
-if DEBUG:
- try:
- EMSCRIPTEN_TEMP_DIR = CANONICAL_TEMP_DIR
- if not os.path.exists(EMSCRIPTEN_TEMP_DIR):
- os.makedirs(EMSCRIPTEN_TEMP_DIR)
- except Exception, e:
- print >> sys.stderr, e, 'Could not create canonical temp dir. Check definition of TEMP_DIR in ~/.emscripten'
+ if self.DEBUG:
+ try:
+ self.EMSCRIPTEN_TEMP_DIR = CANONICAL_TEMP_DIR
+ if not os.path.exists(EMSCRIPTEN_TEMP_DIR):
+ os.makedirs(EMSCRIPTEN_TEMP_DIR)
+ except Exception, e:
+ print >> sys.stderr, e, 'Could not create canonical temp dir. Check definition of TEMP_DIR in ~/.emscripten'
+
+configuration = Configuration()
+DEBUG = configuration.DEBUG
+EMSCRIPTEN_TEMP_DIR = configuration.EMSCRIPTEN_TEMP_DIR
+DEBUG_CACHE = DEBUG and "cache" in DEBUG
if not EMSCRIPTEN_TEMP_DIR:
EMSCRIPTEN_TEMP_DIR = tempfile.mkdtemp(prefix='emscripten_temp_', dir=TEMP_DIR)
@@ -454,9 +458,9 @@ class TempFiles:
finally:
self.clean()
-def ConfigureTempFiles():
+def ConfigureTempFiles(configuration=configuration):
return TempFiles(
- tmp=TEMP_DIR if not DEBUG else EMSCRIPTEN_TEMP_DIR,
+ tmp=TEMP_DIR if not configuration.DEBUG else configuration.EMSCRIPTEN_TEMP_DIR,
saveDebugFiles=os.environ.get('EMCC_DEBUG_SAVE'))
# Utilities