diff options
author | cookedm <cookedm@localhost> | 2007-05-28 17:49:55 +0000 |
---|---|---|
committer | cookedm <cookedm@localhost> | 2007-05-28 17:49:55 +0000 |
commit | 60eed2d138f5fd08fc8fa016debbac097371a47d (patch) | |
tree | a14274bdd33e90ee1fa84c9ccc94fe2d522846ac /numpy/distutils/exec_command.py | |
parent | bfb1633766b1e6b1c72de094aa565c6e6ec0db80 (diff) | |
download | numpy-60eed2d138f5fd08fc8fa016debbac097371a47d.tar.gz |
Better temporary file handling by using one temporary directory for
numpy.distutils, and removing that at exit. Replaces using tempfile.mktemp.
Diffstat (limited to 'numpy/distutils/exec_command.py')
-rw-r--r-- | numpy/distutils/exec_command.py | 29 |
1 files changed, 15 insertions, 14 deletions
diff --git a/numpy/distutils/exec_command.py b/numpy/distutils/exec_command.py index 51ac1a611..7b5d5edb4 100644 --- a/numpy/distutils/exec_command.py +++ b/numpy/distutils/exec_command.py @@ -50,13 +50,14 @@ __all__ = ['exec_command','find_executable'] import os import sys -import tempfile -from numpy.distutils.misc_util import is_sequence +from numpy.distutils.misc_util import is_sequence, make_temp_file +from numpy.distutils import log -############################################################ - -from log import _global_log as log +def temp_file_name(): + fo, name = make_temp_file() + fo.close() + return name ############################################################ @@ -263,17 +264,17 @@ def _exec_command_posix( command, else: command_str = command - tmpfile = tempfile.mktemp() + tmpfile = temp_file_name() stsfile = None if use_tee: - stsfile = tempfile.mktemp() + stsfile = temp_file_name() filter = '' if use_tee == 2: filter = r'| tr -cd "\n" | tr "\n" "."; echo' command_posix = '( %s ; echo $? > %s ) 2>&1 | tee %s %s'\ % (command_str,stsfile,tmpfile,filter) else: - stsfile = tempfile.mktemp() + stsfile = temp_file_name() command_posix = '( %s ; echo $? > %s ) > %s 2>&1'\ % (command_str,stsfile,tmpfile) #command_posix = '( %s ) > %s 2>&1' % (command_str,tmpfile) @@ -310,9 +311,9 @@ def _exec_command_python(command, log.debug('_exec_command_python(...)') python_exe = get_pythonexe() - cmdfile = tempfile.mktemp() - stsfile = tempfile.mktemp() - outfile = tempfile.mktemp() + cmdfile = temp_file_name() + stsfile = temp_file_name() + outfile = temp_file_name() f = open(cmdfile,'w') f.write('import os\n') @@ -396,10 +397,10 @@ def _exec_command( command, use_shell=None, use_tee = None, **env ): so_dup = os.dup(so_fileno) se_dup = os.dup(se_fileno) - outfile = tempfile.mktemp() + outfile = temp_file_name() fout = open(outfile,'w') if using_command: - errfile = tempfile.mktemp() + errfile = temp_file_name() ferr = open(errfile,'w') log.debug('Running %s(%s,%r,%r,os.environ)' \ @@ -588,7 +589,7 @@ def test_posix(**kws): def test_execute_in(**kws): pythonexe = get_pythonexe() - tmpfile = tempfile.mktemp() + tmpfile = temp_file_name() fn = os.path.basename(tmpfile) tmpdir = os.path.dirname(tmpfile) f = open(tmpfile,'w') |