diff options
Diffstat (limited to 'Lib/distutils/spawn.py')
-rw-r--r-- | Lib/distutils/spawn.py | 67 |
1 files changed, 31 insertions, 36 deletions
diff --git a/Lib/distutils/spawn.py b/Lib/distutils/spawn.py index 7306099f6b6..f58c55f9024 100644 --- a/Lib/distutils/spawn.py +++ b/Lib/distutils/spawn.py @@ -6,8 +6,6 @@ Also provides the 'find_executable()' to search the path for a given executable name. """ -__revision__ = "$Id$" - import sys import os @@ -37,8 +35,8 @@ def spawn(cmd, search_path=1, verbose=0, dry_run=0): elif os.name == 'os2': _spawn_os2(cmd, search_path, dry_run=dry_run) else: - raise DistutilsPlatformError, \ - "don't know how to spawn programs on platform '%s'" % os.name + raise DistutilsPlatformError( + "don't know how to spawn programs on platform '%s'" % os.name) def _nt_quote_args(args): """Quote command-line arguments for DOS/Windows conventions. @@ -67,14 +65,14 @@ def _spawn_nt(cmd, search_path=1, verbose=0, dry_run=0): # spawn for NT requires a full path to the .exe try: rc = os.spawnv(os.P_WAIT, executable, cmd) - except OSError, exc: + except OSError as exc: # this seems to happen when the command isn't found - raise DistutilsExecError, \ - "command '%s' failed: %s" % (cmd[0], exc[-1]) + raise DistutilsExecError( + "command '%s' failed: %s" % (cmd[0], exc.args[-1])) if rc != 0: # and this reflects the command running but failing - raise DistutilsExecError, \ - "command '%s' failed with exit status %d" % (cmd[0], rc) + raise DistutilsExecError( + "command '%s' failed with exit status %d" % (cmd[0], rc)) def _spawn_os2(cmd, search_path=1, verbose=0, dry_run=0): executable = cmd[0] @@ -86,15 +84,15 @@ def _spawn_os2(cmd, search_path=1, verbose=0, dry_run=0): # spawnv for OS/2 EMX requires a full path to the .exe try: rc = os.spawnv(os.P_WAIT, executable, cmd) - except OSError, exc: + except OSError as exc: # this seems to happen when the command isn't found - raise DistutilsExecError, \ - "command '%s' failed: %s" % (cmd[0], exc[-1]) + raise DistutilsExecError( + "command '%s' failed: %s" % (cmd[0], exc.args[-1])) if rc != 0: # and this reflects the command running but failing log.debug("command '%s' failed with exit status %d" % (cmd[0], rc)) - raise DistutilsExecError, \ - "command '%s' failed with exit status %d" % (cmd[0], rc) + raise DistutilsExecError( + "command '%s' failed with exit status %d" % (cmd[0], rc)) if sys.platform == 'darwin': from distutils import sysconfig @@ -129,50 +127,46 @@ def _spawn_posix(cmd, search_path=1, verbose=0, dry_run=0): exec_fn = search_path and os.execvpe or os.execve exec_args.append(env) pid = os.fork() - - if pid == 0: # in the child + if pid == 0: # in the child try: exec_fn(*exec_args) - except OSError, e: - sys.stderr.write("unable to execute %s: %s\n" % - (cmd[0], e.strerror)) + except OSError as e: + sys.stderr.write("unable to execute %s: %s\n" + % (cmd[0], e.strerror)) os._exit(1) sys.stderr.write("unable to execute %s for unknown reasons" % cmd[0]) os._exit(1) - else: # in the parent + else: # in the parent # Loop until the child either exits or is terminated by a signal # (ie. keep waiting if it's merely stopped) - while 1: + while True: try: pid, status = os.waitpid(pid, 0) - except OSError, exc: + except OSError as exc: import errno if exc.errno == errno.EINTR: continue - raise DistutilsExecError, \ - "command '%s' failed: %s" % (cmd[0], exc[-1]) + raise DistutilsExecError( + "command '%s' failed: %s" % (cmd[0], exc.args[-1])) if os.WIFSIGNALED(status): - raise DistutilsExecError, \ - "command '%s' terminated by signal %d" % \ - (cmd[0], os.WTERMSIG(status)) - + raise DistutilsExecError( + "command '%s' terminated by signal %d" + % (cmd[0], os.WTERMSIG(status))) elif os.WIFEXITED(status): exit_status = os.WEXITSTATUS(status) if exit_status == 0: return # hey, it succeeded! else: - raise DistutilsExecError, \ - "command '%s' failed with exit status %d" % \ - (cmd[0], exit_status) - + raise DistutilsExecError( + "command '%s' failed with exit status %d" + % (cmd[0], exit_status)) elif os.WIFSTOPPED(status): continue - else: - raise DistutilsExecError, \ - "unknown error executing '%s': termination status %d" % \ - (cmd[0], status) + raise DistutilsExecError( + "unknown error executing '%s': termination status %d" + % (cmd[0], status)) def find_executable(executable, path=None): """Tries to find 'executable' in the directories listed in 'path'. @@ -182,6 +176,7 @@ def find_executable(executable, path=None): """ if path is None: path = os.environ['PATH'] + paths = path.split(os.pathsep) base, ext = os.path.splitext(executable) |