diff options
author | Chad Austin <chad@imvu.com> | 2013-01-31 18:17:14 -0800 |
---|---|---|
committer | Chad Austin <chad@imvu.com> | 2013-03-04 19:31:47 -0800 |
commit | 5ba10fe45e42ba1f6f92b7db5e34117e655bfa2d (patch) | |
tree | b6aeac88a633db4a07becd530917660f036aeb99 | |
parent | 730294d0d106a4cf2d40bad94bba33f53d944ebc (diff) |
Get the TempFiles object from the Configuration
-rwxr-xr-x | emscripten.py | 2 | ||||
-rw-r--r-- | tools/js_optimizer.py | 3 | ||||
-rw-r--r-- | tools/shared.py | 70 |
3 files changed, 38 insertions, 37 deletions
diff --git a/emscripten.py b/emscripten.py index 1a87c788..011bc22f 100755 --- a/emscripten.py +++ b/emscripten.py @@ -21,7 +21,7 @@ def path_from_root(*pathelems): return os.path.join(__rootpath__, *pathelems) configuration = shared.Configuration(environ=os.environ) -temp_files = shared.make_temp_files() +temp_files = configuration.get_temp_files() def scan(ll, settings): # blockaddress(@main, %23) diff --git a/tools/js_optimizer.py b/tools/js_optimizer.py index f2d3b7db..ad3a1f79 100644 --- a/tools/js_optimizer.py +++ b/tools/js_optimizer.py @@ -2,7 +2,8 @@ import os, sys, subprocess, multiprocessing, re import shared -temp_files = shared.make_temp_files() +configuration = shared.configuration +temp_files = configuration.get_temp_files() __rootpath__ = os.path.abspath(os.path.dirname(os.path.dirname(__file__))) def path_from_root(*pathelems): diff --git a/tools/shared.py b/tools/shared.py index 9b2b4561..f0c79dae 100644 --- a/tools/shared.py +++ b/tools/shared.py @@ -317,10 +317,45 @@ class Configuration: except Exception, e: print >> sys.stderr, e, 'Could not create canonical temp dir. Check definition of TEMP_DIR in ~/.emscripten' + def get_temp_files(self): + return TempFiles( + tmp=self.TEMP_DIR if not self.DEBUG else self.EMSCRIPTEN_TEMP_DIR, + save_debug_files=os.environ.get('EMCC_DEBUG_SAVE')) + def debug_log(self, msg): if self.DEBUG: print >> sys.stderr, msg +class TempFiles: + def __init__(self, tmp, save_debug_files=False): + self.tmp = tmp + self.save_debug_files = save_debug_files + + self.to_clean = [] + + def note(self, filename): + self.to_clean.append(filename) + + def get(self, suffix): + """Returns a named temp file with the given prefix.""" + named_file = tempfile.NamedTemporaryFile(dir=self.tmp, suffix=suffix, delete=False) + self.note(named_file.name) + return named_file + + def clean(self): + if self.save_debug_files: + print >> sys.stderr, 'not cleaning up temp files since in debug-save mode, see them in %s' % (self.tmp,) + return + for filename in self.to_clean: + try_delete(filename) + self.to_clean = [] + + def run_and_clean(self, func): + try: + return func() + finally: + self.clean() + configuration = Configuration(environ=os.environ) DEBUG = configuration.DEBUG EMSCRIPTEN_TEMP_DIR = configuration.EMSCRIPTEN_TEMP_DIR @@ -435,41 +470,6 @@ def try_delete(filename): except: pass -class TempFiles: - def __init__(self, tmp, save_debug_files=False): - self.tmp = tmp - self.save_debug_files = save_debug_files - - self.to_clean = [] - - def note(self, filename): - self.to_clean.append(filename) - - def get(self, suffix): - """Returns a named temp file with the given prefix.""" - named_file = tempfile.NamedTemporaryFile(dir=self.tmp, suffix=suffix, delete=False) - self.note(named_file.name) - return named_file - - def clean(self): - if self.save_debug_files: - print >> sys.stderr, 'not cleaning up temp files since in debug-save mode, see them in %s' % (self.tmp,) - return - for filename in self.to_clean: - try_delete(filename) - self.to_clean = [] - - def run_and_clean(self, func): - try: - return func() - finally: - self.clean() - -def make_temp_files(configuration=configuration): - return TempFiles( - tmp=configuration.TEMP_DIR if not configuration.DEBUG else configuration.EMSCRIPTEN_TEMP_DIR, - save_debug_files=os.environ.get('EMCC_DEBUG_SAVE')) - # Utilities def check_engine(engine): |