Get the TempFiles object from the Configuration

This commit is contained in:
Chad Austin 2013-01-31 18:17:14 -08:00
Родитель 730294d0d1
Коммит 5ba10fe45e
3 изменённых файлов: 38 добавлений и 37 удалений

Просмотреть файл

@ -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)

Просмотреть файл

@ -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):

Просмотреть файл

@ -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):