Changeset 391 for python/trunk/Lib/distutils/spawn.py
- Timestamp:
- Mar 19, 2014, 11:31:01 PM (11 years ago)
- Location:
- python/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
python/trunk
-
Property svn:mergeinfo
set to
/python/vendor/Python-2.7.6 merged eligible /python/vendor/current merged eligible
-
Property svn:mergeinfo
set to
-
python/trunk/Lib/distutils/spawn.py
r2 r391 7 7 """ 8 8 9 # This module should be kept compatible with Python 2.1. 9 __revision__ = "$Id$" 10 10 11 __revision__ = "$Id: spawn.py 37828 2004-11-10 22:23:15Z loewis $" 11 import sys 12 import os 12 13 13 import sys, os, string 14 from distutils.errors import * 14 from distutils.errors import DistutilsPlatformError, DistutilsExecError 15 15 from distutils import log 16 16 17 def spawn (cmd, 18 search_path=1, 19 verbose=0, 20 dry_run=0): 17 def spawn(cmd, search_path=1, verbose=0, dry_run=0): 18 """Run another program, specified as a command list 'cmd', in a new process. 21 19 22 """Run another program, specified as a command list 'cmd', in a new 23 process. 'cmd' is just the argument list for the new process, ie. 20 'cmd' is just the argument list for the new process, ie. 24 21 cmd[0] is the program to run and cmd[1:] are the rest of its arguments. 25 22 There is no way to run a program with a name different from that of its … … 44 41 "don't know how to spawn programs on platform '%s'" % os.name 45 42 46 # spawn () 43 def _nt_quote_args(args): 44 """Quote command-line arguments for DOS/Windows conventions. 47 45 48 49 def _nt_quote_args (args): 50 """Quote command-line arguments for DOS/Windows conventions: just 51 wraps every argument which contains blanks in double quotes, and 46 Just wraps every argument which contains blanks in double quotes, and 52 47 returns a new argument list. 53 48 """ 54 55 49 # XXX this doesn't seem very robust to me -- but if the Windows guys 56 50 # say it'll work, I guess I'll have to accept it. (What if an arg … … 58 52 # have to be escaped? Is there an escaping mechanism other than 59 53 # quoting?) 60 61 for i in range(len(args)): 62 if string.find(args[i], ' ') != -1: 63 args[i] = '"%s"' % args[i] 54 for i, arg in enumerate(args): 55 if ' ' in arg: 56 args[i] = '"%s"' % arg 64 57 return args 65 58 66 def _spawn_nt (cmd, 67 search_path=1, 68 verbose=0, 69 dry_run=0): 70 59 def _spawn_nt(cmd, search_path=1, verbose=0, dry_run=0): 71 60 executable = cmd[0] 72 61 cmd = _nt_quote_args(cmd) … … 74 63 # either we find one or it stays the same 75 64 executable = find_executable(executable) or executable 76 log.info( string.join([executable] + cmd[1:], ' '))65 log.info(' '.join([executable] + cmd[1:])) 77 66 if not dry_run: 78 67 # spawn for NT requires a full path to the .exe … … 88 77 "command '%s' failed with exit status %d" % (cmd[0], rc) 89 78 90 91 def _spawn_os2 (cmd, 92 search_path=1, 93 verbose=0, 94 dry_run=0): 95 79 def _spawn_os2(cmd, search_path=1, verbose=0, dry_run=0): 96 80 executable = cmd[0] 97 #cmd = _nt_quote_args(cmd)98 81 if search_path: 99 82 # either we find one or it stays the same 100 83 executable = find_executable(executable) or executable 101 log.info( string.join([executable] + cmd[1:], ' '))84 log.info(' '.join([executable] + cmd[1:])) 102 85 if not dry_run: 103 86 # spawnv for OS/2 EMX requires a full path to the .exe … … 110 93 if rc != 0: 111 94 # and this reflects the command running but failing 112 print "command '%s' failed with exit status %d" % (cmd[0], rc)95 log.debug("command '%s' failed with exit status %d" % (cmd[0], rc)) 113 96 raise DistutilsExecError, \ 114 97 "command '%s' failed with exit status %d" % (cmd[0], rc) 115 98 99 if sys.platform == 'darwin': 100 from distutils import sysconfig 101 _cfg_target = None 102 _cfg_target_split = None 116 103 117 def _spawn_posix (cmd, 118 search_path=1, 119 verbose=0, 120 dry_run=0): 121 122 log.info(string.join(cmd, ' ')) 104 def _spawn_posix(cmd, search_path=1, verbose=0, dry_run=0): 105 log.info(' '.join(cmd)) 123 106 if dry_run: 124 107 return 125 108 exec_fn = search_path and os.execvp or os.execv 126 109 exec_args = [cmd[0], cmd] 110 if sys.platform == 'darwin': 111 global _cfg_target, _cfg_target_split 112 if _cfg_target is None: 113 _cfg_target = sysconfig.get_config_var( 114 'MACOSX_DEPLOYMENT_TARGET') or '' 115 if _cfg_target: 116 _cfg_target_split = [int(x) for x in _cfg_target.split('.')] 117 if _cfg_target: 118 # ensure that the deployment target of build process is not less 119 # than that used when the interpreter was built. This ensures 120 # extension modules are built with correct compatibility values 121 cur_target = os.environ.get('MACOSX_DEPLOYMENT_TARGET', _cfg_target) 122 if _cfg_target_split > [int(x) for x in cur_target.split('.')]: 123 my_msg = ('$MACOSX_DEPLOYMENT_TARGET mismatch: ' 124 'now "%s" but "%s" during configure' 125 % (cur_target, _cfg_target)) 126 raise DistutilsPlatformError(my_msg) 127 env = dict(os.environ, 128 MACOSX_DEPLOYMENT_TARGET=cur_target) 129 exec_fn = search_path and os.execvpe or os.execve 130 exec_args.append(env) 127 131 pid = os.fork() 128 132 129 if pid == 0: 133 if pid == 0: # in the child 130 134 try: 131 #print "cmd[0] =", cmd[0] 132 #print "cmd =", cmd 133 exec_fn(cmd[0], cmd) 135 exec_fn(*exec_args) 134 136 except OSError, e: 135 137 sys.stderr.write("unable to execute %s: %s\n" % … … 139 141 sys.stderr.write("unable to execute %s for unknown reasons" % cmd[0]) 140 142 os._exit(1) 141 142 143 else: # in the parent 143 else: # in the parent 144 144 # Loop until the child either exits or is terminated by a signal 145 145 # (ie. keep waiting if it's merely stopped) 146 146 while 1: 147 147 try: 148 (pid, status)= os.waitpid(pid, 0)148 pid, status = os.waitpid(pid, 0) 149 149 except OSError, exc: 150 150 import errno … … 161 161 exit_status = os.WEXITSTATUS(status) 162 162 if exit_status == 0: 163 return 163 return # hey, it succeeded! 164 164 else: 165 165 raise DistutilsExecError, \ … … 174 174 "unknown error executing '%s': termination status %d" % \ 175 175 (cmd[0], status) 176 # _spawn_posix ()177 178 176 179 177 def find_executable(executable, path=None): 180 """Tr y to find 'executable' in the directories listed in 'path' (a181 string listing directories separated by 'os.pathsep'; defaults to 182 os.environ['PATH']). Returns the complete filename or None if not183 found.178 """Tries to find 'executable' in the directories listed in 'path'. 179 180 A string listing directories separated by 'os.pathsep'; defaults to 181 os.environ['PATH']. Returns the complete filename or None if not found. 184 182 """ 185 183 if path is None: 186 184 path = os.environ['PATH'] 187 paths = string.split(path, os.pathsep) 188 (base, ext) = os.path.splitext(executable) 185 paths = path.split(os.pathsep) 186 base, ext = os.path.splitext(executable) 187 189 188 if (sys.platform == 'win32' or os.name == 'os2') and (ext != '.exe'): 190 189 executable = executable + '.exe' 190 191 191 if not os.path.isfile(executable): 192 192 for p in paths: … … 198 198 else: 199 199 return executable 200 201 # find_executable()
Note:
See TracChangeset
for help on using the changeset viewer.