annotate Lib/distutils/spawn.py @ 79691:05c8928362ee

Merge __next__ method link fixes with 3.3.
author Ezio Melotti <ezio.melotti@gmail.com>
date Fri, 12 Oct 2012 13:46:37 +0300
parents 147b9d530dd0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
11198
e8b24cd17df2 Module to spawn sub-commands in a platform-independent way.
Greg Ward <gward@python.net>
parents:
diff changeset
1 """distutils.spawn
e8b24cd17df2 Module to spawn sub-commands in a platform-independent way.
Greg Ward <gward@python.net>
parents:
diff changeset
2
e8b24cd17df2 Module to spawn sub-commands in a platform-independent way.
Greg Ward <gward@python.net>
parents:
diff changeset
3 Provides the 'spawn()' function, a front-end to various platform-
13803
e8b22bc88d95 Rene Liebscher: factor 'find_executable()' out of '_spawn_nt()'.
Greg Ward <gward@python.net>
parents: 12058
diff changeset
4 specific functions for launching another program in a sub-process.
e8b22bc88d95 Rene Liebscher: factor 'find_executable()' out of '_spawn_nt()'.
Greg Ward <gward@python.net>
parents: 12058
diff changeset
5 Also provides the 'find_executable()' to search the path for a given
14861
09c14ae5c2f5 Reformat docstrings.
Greg Ward <gward@python.net>
parents: 13803
diff changeset
6 executable name.
09c14ae5c2f5 Reformat docstrings.
Greg Ward <gward@python.net>
parents: 13803
diff changeset
7 """
11198
e8b24cd17df2 Module to spawn sub-commands in a platform-independent way.
Greg Ward <gward@python.net>
parents:
diff changeset
8
54522
5e4d070565e7 Merged revisions 73147 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 44542
diff changeset
9 import sys
5e4d070565e7 Merged revisions 73147 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 44542
diff changeset
10 import os
5e4d070565e7 Merged revisions 73147 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 44542
diff changeset
11
5e4d070565e7 Merged revisions 73147 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 44542
diff changeset
12 from distutils.errors import DistutilsPlatformError, DistutilsExecError
23668
ca87119255eb Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 21851
diff changeset
13 from distutils import log
11198
e8b24cd17df2 Module to spawn sub-commands in a platform-independent way.
Greg Ward <gward@python.net>
parents:
diff changeset
14
43026
a6d3930b5613 General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents: 41480
diff changeset
15 def spawn(cmd, search_path=1, verbose=0, dry_run=0):
54522
5e4d070565e7 Merged revisions 73147 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 44542
diff changeset
16 """Run another program, specified as a command list 'cmd', in a new process.
5e4d070565e7 Merged revisions 73147 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 44542
diff changeset
17
5e4d070565e7 Merged revisions 73147 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 44542
diff changeset
18 'cmd' is just the argument list for the new process, ie.
14861
09c14ae5c2f5 Reformat docstrings.
Greg Ward <gward@python.net>
parents: 13803
diff changeset
19 cmd[0] is the program to run and cmd[1:] are the rest of its arguments.
09c14ae5c2f5 Reformat docstrings.
Greg Ward <gward@python.net>
parents: 13803
diff changeset
20 There is no way to run a program with a name different from that of its
09c14ae5c2f5 Reformat docstrings.
Greg Ward <gward@python.net>
parents: 13803
diff changeset
21 executable.
11198
e8b24cd17df2 Module to spawn sub-commands in a platform-independent way.
Greg Ward <gward@python.net>
parents:
diff changeset
22
26324
05d6ade3e92b Reflow comment
Andrew M. Kuchling <amk@amk.ca>
parents: 26285
diff changeset
23 If 'search_path' is true (the default), the system's executable
05d6ade3e92b Reflow comment
Andrew M. Kuchling <amk@amk.ca>
parents: 26285
diff changeset
24 search path will be used to find the program; otherwise, cmd[0]
05d6ade3e92b Reflow comment
Andrew M. Kuchling <amk@amk.ca>
parents: 26285
diff changeset
25 must be the exact path to the executable. If 'dry_run' is true,
14861
09c14ae5c2f5 Reformat docstrings.
Greg Ward <gward@python.net>
parents: 13803
diff changeset
26 the command will not actually be run.
11198
e8b24cd17df2 Module to spawn sub-commands in a platform-independent way.
Greg Ward <gward@python.net>
parents:
diff changeset
27
14861
09c14ae5c2f5 Reformat docstrings.
Greg Ward <gward@python.net>
parents: 13803
diff changeset
28 Raise DistutilsExecError if running the program fails in any way; just
09c14ae5c2f5 Reformat docstrings.
Greg Ward <gward@python.net>
parents: 13803
diff changeset
29 return on success.
09c14ae5c2f5 Reformat docstrings.
Greg Ward <gward@python.net>
parents: 13803
diff changeset
30 """
11198
e8b24cd17df2 Module to spawn sub-commands in a platform-independent way.
Greg Ward <gward@python.net>
parents:
diff changeset
31 if os.name == 'posix':
23668
ca87119255eb Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 21851
diff changeset
32 _spawn_posix(cmd, search_path, dry_run=dry_run)
11257
9286d3e1474c [from 1999/08/28]
Greg Ward <gward@python.net>
parents: 11250
diff changeset
33 elif os.name == 'nt':
23668
ca87119255eb Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 21851
diff changeset
34 _spawn_nt(cmd, search_path, dry_run=dry_run)
11198
e8b24cd17df2 Module to spawn sub-commands in a platform-independent way.
Greg Ward <gward@python.net>
parents:
diff changeset
35 else:
43026
a6d3930b5613 General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents: 41480
diff changeset
36 raise DistutilsPlatformError(
a6d3930b5613 General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents: 41480
diff changeset
37 "don't know how to spawn programs on platform '%s'" % os.name)
11198
e8b24cd17df2 Module to spawn sub-commands in a platform-independent way.
Greg Ward <gward@python.net>
parents:
diff changeset
38
54522
5e4d070565e7 Merged revisions 73147 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 44542
diff changeset
39 def _nt_quote_args(args):
5e4d070565e7 Merged revisions 73147 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 44542
diff changeset
40 """Quote command-line arguments for DOS/Windows conventions.
11257
9286d3e1474c [from 1999/08/28]
Greg Ward <gward@python.net>
parents: 11250
diff changeset
41
54522
5e4d070565e7 Merged revisions 73147 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 44542
diff changeset
42 Just wraps every argument which contains blanks in double quotes, and
14861
09c14ae5c2f5 Reformat docstrings.
Greg Ward <gward@python.net>
parents: 13803
diff changeset
43 returns a new argument list.
09c14ae5c2f5 Reformat docstrings.
Greg Ward <gward@python.net>
parents: 13803
diff changeset
44 """
11933
68e0ef052815 Added '_nt_quote_args()' to deal with whitespace in command-line arguments
Greg Ward <gward@python.net>
parents: 11897
diff changeset
45 # XXX this doesn't seem very robust to me -- but if the Windows guys
68e0ef052815 Added '_nt_quote_args()' to deal with whitespace in command-line arguments
Greg Ward <gward@python.net>
parents: 11897
diff changeset
46 # say it'll work, I guess I'll have to accept it. (What if an arg
68e0ef052815 Added '_nt_quote_args()' to deal with whitespace in command-line arguments
Greg Ward <gward@python.net>
parents: 11897
diff changeset
47 # contains quotes? What other magic characters, other than spaces,
68e0ef052815 Added '_nt_quote_args()' to deal with whitespace in command-line arguments
Greg Ward <gward@python.net>
parents: 11897
diff changeset
48 # have to be escaped? Is there an escaping mechanism other than
68e0ef052815 Added '_nt_quote_args()' to deal with whitespace in command-line arguments
Greg Ward <gward@python.net>
parents: 11897
diff changeset
49 # quoting?)
54522
5e4d070565e7 Merged revisions 73147 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 44542
diff changeset
50 for i, arg in enumerate(args):
5e4d070565e7 Merged revisions 73147 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 44542
diff changeset
51 if ' ' in arg:
5e4d070565e7 Merged revisions 73147 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 44542
diff changeset
52 args[i] = '"%s"' % arg
12058
c6cb0d266839 Duh, it helps if '_nt_quote_args()' actually returns the mutated list,
Greg Ward <gward@python.net>
parents: 12043
diff changeset
53 return args
11933
68e0ef052815 Added '_nt_quote_args()' to deal with whitespace in command-line arguments
Greg Ward <gward@python.net>
parents: 11897
diff changeset
54
43026
a6d3930b5613 General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents: 41480
diff changeset
55 def _spawn_nt(cmd, search_path=1, verbose=0, dry_run=0):
11250
b3f1abd3027f Patch from Perry Stoll: support for Windows.
Greg Ward <gward@python.net>
parents: 11198
diff changeset
56 executable = cmd[0]
14861
09c14ae5c2f5 Reformat docstrings.
Greg Ward <gward@python.net>
parents: 13803
diff changeset
57 cmd = _nt_quote_args(cmd)
11250
b3f1abd3027f Patch from Perry Stoll: support for Windows.
Greg Ward <gward@python.net>
parents: 11198
diff changeset
58 if search_path:
13803
e8b22bc88d95 Rene Liebscher: factor 'find_executable()' out of '_spawn_nt()'.
Greg Ward <gward@python.net>
parents: 12058
diff changeset
59 # either we find one or it stays the same
21267
7a7f557b4d54 Whitespace normalization.
Fred Drake <fdrake@acm.org>
parents: 14861
diff changeset
60 executable = find_executable(executable) or executable
41480
99027c2b3fd2 Remove functions in string module that are also string methods. Also remove:
Neal Norwitz <nnorwitz@gmail.com>
parents: 40775
diff changeset
61 log.info(' '.join([executable] + cmd[1:]))
11250
b3f1abd3027f Patch from Perry Stoll: support for Windows.
Greg Ward <gward@python.net>
parents: 11198
diff changeset
62 if not dry_run:
b3f1abd3027f Patch from Perry Stoll: support for Windows.
Greg Ward <gward@python.net>
parents: 11198
diff changeset
63 # spawn for NT requires a full path to the .exe
11665
e998b350a4bb Catch OSError from 'spawnv()' in '_spawn_nt()'.
Greg Ward <gward@python.net>
parents: 11257
diff changeset
64 try:
14861
09c14ae5c2f5 Reformat docstrings.
Greg Ward <gward@python.net>
parents: 13803
diff changeset
65 rc = os.spawnv(os.P_WAIT, executable, cmd)
40587
6b18a095c2e7 SF patch 1631942 by Collin Winter:
Guido van Rossum <guido@python.org>
parents: 33965
diff changeset
66 except OSError as exc:
11665
e998b350a4bb Catch OSError from 'spawnv()' in '_spawn_nt()'.
Greg Ward <gward@python.net>
parents: 11257
diff changeset
67 # this seems to happen when the command isn't found
43026
a6d3930b5613 General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents: 41480
diff changeset
68 raise DistutilsExecError(
44542
d0465e782b01 Fix more exception slicing.
Georg Brandl <georg@python.org>
parents: 43026
diff changeset
69 "command '%s' failed: %s" % (cmd[0], exc.args[-1]))
11250
b3f1abd3027f Patch from Perry Stoll: support for Windows.
Greg Ward <gward@python.net>
parents: 11198
diff changeset
70 if rc != 0:
11665
e998b350a4bb Catch OSError from 'spawnv()' in '_spawn_nt()'.
Greg Ward <gward@python.net>
parents: 11257
diff changeset
71 # and this reflects the command running but failing
43026
a6d3930b5613 General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents: 41480
diff changeset
72 raise DistutilsExecError(
a6d3930b5613 General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents: 41480
diff changeset
73 "command '%s' failed with exit status %d" % (cmd[0], rc))
11198
e8b24cd17df2 Module to spawn sub-commands in a platform-independent way.
Greg Ward <gward@python.net>
parents:
diff changeset
74
71049
b95eee310931 Issue #9516: Change distutils to no longer globally attempt to check and
Ned Deily <nad@acm.org>
parents: 54522
diff changeset
75 if sys.platform == 'darwin':
b95eee310931 Issue #9516: Change distutils to no longer globally attempt to check and
Ned Deily <nad@acm.org>
parents: 54522
diff changeset
76 from distutils import sysconfig
b95eee310931 Issue #9516: Change distutils to no longer globally attempt to check and
Ned Deily <nad@acm.org>
parents: 54522
diff changeset
77 _cfg_target = None
b95eee310931 Issue #9516: Change distutils to no longer globally attempt to check and
Ned Deily <nad@acm.org>
parents: 54522
diff changeset
78 _cfg_target_split = None
b95eee310931 Issue #9516: Change distutils to no longer globally attempt to check and
Ned Deily <nad@acm.org>
parents: 54522
diff changeset
79
43026
a6d3930b5613 General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents: 41480
diff changeset
80 def _spawn_posix(cmd, search_path=1, verbose=0, dry_run=0):
41480
99027c2b3fd2 Remove functions in string module that are also string methods. Also remove:
Neal Norwitz <nnorwitz@gmail.com>
parents: 40775
diff changeset
81 log.info(' '.join(cmd))
11198
e8b24cd17df2 Module to spawn sub-commands in a platform-independent way.
Greg Ward <gward@python.net>
parents:
diff changeset
82 if dry_run:
e8b24cd17df2 Module to spawn sub-commands in a platform-independent way.
Greg Ward <gward@python.net>
parents:
diff changeset
83 return
e8b24cd17df2 Module to spawn sub-commands in a platform-independent way.
Greg Ward <gward@python.net>
parents:
diff changeset
84 exec_fn = search_path and os.execvp or os.execv
71049
b95eee310931 Issue #9516: Change distutils to no longer globally attempt to check and
Ned Deily <nad@acm.org>
parents: 54522
diff changeset
85 exec_args = [cmd[0], cmd]
b95eee310931 Issue #9516: Change distutils to no longer globally attempt to check and
Ned Deily <nad@acm.org>
parents: 54522
diff changeset
86 if sys.platform == 'darwin':
b95eee310931 Issue #9516: Change distutils to no longer globally attempt to check and
Ned Deily <nad@acm.org>
parents: 54522
diff changeset
87 global _cfg_target, _cfg_target_split
b95eee310931 Issue #9516: Change distutils to no longer globally attempt to check and
Ned Deily <nad@acm.org>
parents: 54522
diff changeset
88 if _cfg_target is None:
b95eee310931 Issue #9516: Change distutils to no longer globally attempt to check and
Ned Deily <nad@acm.org>
parents: 54522
diff changeset
89 _cfg_target = sysconfig.get_config_var(
b95eee310931 Issue #9516: Change distutils to no longer globally attempt to check and
Ned Deily <nad@acm.org>
parents: 54522
diff changeset
90 'MACOSX_DEPLOYMENT_TARGET') or ''
b95eee310931 Issue #9516: Change distutils to no longer globally attempt to check and
Ned Deily <nad@acm.org>
parents: 54522
diff changeset
91 if _cfg_target:
b95eee310931 Issue #9516: Change distutils to no longer globally attempt to check and
Ned Deily <nad@acm.org>
parents: 54522
diff changeset
92 _cfg_target_split = [int(x) for x in _cfg_target.split('.')]
b95eee310931 Issue #9516: Change distutils to no longer globally attempt to check and
Ned Deily <nad@acm.org>
parents: 54522
diff changeset
93 if _cfg_target:
b95eee310931 Issue #9516: Change distutils to no longer globally attempt to check and
Ned Deily <nad@acm.org>
parents: 54522
diff changeset
94 # ensure that the deployment target of build process is not less
b95eee310931 Issue #9516: Change distutils to no longer globally attempt to check and
Ned Deily <nad@acm.org>
parents: 54522
diff changeset
95 # than that used when the interpreter was built. This ensures
b95eee310931 Issue #9516: Change distutils to no longer globally attempt to check and
Ned Deily <nad@acm.org>
parents: 54522
diff changeset
96 # extension modules are built with correct compatibility values
b95eee310931 Issue #9516: Change distutils to no longer globally attempt to check and
Ned Deily <nad@acm.org>
parents: 54522
diff changeset
97 cur_target = os.environ.get('MACOSX_DEPLOYMENT_TARGET', _cfg_target)
b95eee310931 Issue #9516: Change distutils to no longer globally attempt to check and
Ned Deily <nad@acm.org>
parents: 54522
diff changeset
98 if _cfg_target_split > [int(x) for x in cur_target.split('.')]:
b95eee310931 Issue #9516: Change distutils to no longer globally attempt to check and
Ned Deily <nad@acm.org>
parents: 54522
diff changeset
99 my_msg = ('$MACOSX_DEPLOYMENT_TARGET mismatch: '
b95eee310931 Issue #9516: Change distutils to no longer globally attempt to check and
Ned Deily <nad@acm.org>
parents: 54522
diff changeset
100 'now "%s" but "%s" during configure'
b95eee310931 Issue #9516: Change distutils to no longer globally attempt to check and
Ned Deily <nad@acm.org>
parents: 54522
diff changeset
101 % (cur_target, _cfg_target))
b95eee310931 Issue #9516: Change distutils to no longer globally attempt to check and
Ned Deily <nad@acm.org>
parents: 54522
diff changeset
102 raise DistutilsPlatformError(my_msg)
b95eee310931 Issue #9516: Change distutils to no longer globally attempt to check and
Ned Deily <nad@acm.org>
parents: 54522
diff changeset
103 env = dict(os.environ,
b95eee310931 Issue #9516: Change distutils to no longer globally attempt to check and
Ned Deily <nad@acm.org>
parents: 54522
diff changeset
104 MACOSX_DEPLOYMENT_TARGET=cur_target)
b95eee310931 Issue #9516: Change distutils to no longer globally attempt to check and
Ned Deily <nad@acm.org>
parents: 54522
diff changeset
105 exec_fn = search_path and os.execvpe or os.execve
b95eee310931 Issue #9516: Change distutils to no longer globally attempt to check and
Ned Deily <nad@acm.org>
parents: 54522
diff changeset
106 exec_args.append(env)
14861
09c14ae5c2f5 Reformat docstrings.
Greg Ward <gward@python.net>
parents: 13803
diff changeset
107 pid = os.fork()
43026
a6d3930b5613 General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents: 41480
diff changeset
108 if pid == 0: # in the child
11198
e8b24cd17df2 Module to spawn sub-commands in a platform-independent way.
Greg Ward <gward@python.net>
parents:
diff changeset
109 try:
71049
b95eee310931 Issue #9516: Change distutils to no longer globally attempt to check and
Ned Deily <nad@acm.org>
parents: 54522
diff changeset
110 exec_fn(*exec_args)
40587
6b18a095c2e7 SF patch 1631942 by Collin Winter:
Guido van Rossum <guido@python.org>
parents: 33965
diff changeset
111 except OSError as e:
43026
a6d3930b5613 General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents: 41480
diff changeset
112 sys.stderr.write("unable to execute %s: %s\n"
a6d3930b5613 General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents: 41480
diff changeset
113 % (cmd[0], e.strerror))
14861
09c14ae5c2f5 Reformat docstrings.
Greg Ward <gward@python.net>
parents: 13803
diff changeset
114 os._exit(1)
21267
7a7f557b4d54 Whitespace normalization.
Fred Drake <fdrake@acm.org>
parents: 14861
diff changeset
115
14861
09c14ae5c2f5 Reformat docstrings.
Greg Ward <gward@python.net>
parents: 13803
diff changeset
116 sys.stderr.write("unable to execute %s for unknown reasons" % cmd[0])
09c14ae5c2f5 Reformat docstrings.
Greg Ward <gward@python.net>
parents: 13803
diff changeset
117 os._exit(1)
43026
a6d3930b5613 General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents: 41480
diff changeset
118 else: # in the parent
11198
e8b24cd17df2 Module to spawn sub-commands in a platform-independent way.
Greg Ward <gward@python.net>
parents:
diff changeset
119 # Loop until the child either exits or is terminated by a signal
e8b24cd17df2 Module to spawn sub-commands in a platform-independent way.
Greg Ward <gward@python.net>
parents:
diff changeset
120 # (ie. keep waiting if it's merely stopped)
43026
a6d3930b5613 General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents: 41480
diff changeset
121 while True:
31586
54685d9ffb87 Make _spawn_posix be ready for EINTR. waitpid(2) can be interrupted
Hye-Shik Chang <hyeshik@gmail.com>
parents: 26324
diff changeset
122 try:
54522
5e4d070565e7 Merged revisions 73147 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 44542
diff changeset
123 pid, status = os.waitpid(pid, 0)
40587
6b18a095c2e7 SF patch 1631942 by Collin Winter:
Guido van Rossum <guido@python.org>
parents: 33965
diff changeset
124 except OSError as exc:
31586
54685d9ffb87 Make _spawn_posix be ready for EINTR. waitpid(2) can be interrupted
Hye-Shik Chang <hyeshik@gmail.com>
parents: 26324
diff changeset
125 import errno
54685d9ffb87 Make _spawn_posix be ready for EINTR. waitpid(2) can be interrupted
Hye-Shik Chang <hyeshik@gmail.com>
parents: 26324
diff changeset
126 if exc.errno == errno.EINTR:
54685d9ffb87 Make _spawn_posix be ready for EINTR. waitpid(2) can be interrupted
Hye-Shik Chang <hyeshik@gmail.com>
parents: 26324
diff changeset
127 continue
43026
a6d3930b5613 General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents: 41480
diff changeset
128 raise DistutilsExecError(
44542
d0465e782b01 Fix more exception slicing.
Georg Brandl <georg@python.org>
parents: 43026
diff changeset
129 "command '%s' failed: %s" % (cmd[0], exc.args[-1]))
14861
09c14ae5c2f5 Reformat docstrings.
Greg Ward <gward@python.net>
parents: 13803
diff changeset
130 if os.WIFSIGNALED(status):
43026
a6d3930b5613 General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents: 41480
diff changeset
131 raise DistutilsExecError(
a6d3930b5613 General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents: 41480
diff changeset
132 "command '%s' terminated by signal %d"
a6d3930b5613 General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents: 41480
diff changeset
133 % (cmd[0], os.WTERMSIG(status)))
14861
09c14ae5c2f5 Reformat docstrings.
Greg Ward <gward@python.net>
parents: 13803
diff changeset
134 elif os.WIFEXITED(status):
09c14ae5c2f5 Reformat docstrings.
Greg Ward <gward@python.net>
parents: 13803
diff changeset
135 exit_status = os.WEXITSTATUS(status)
11198
e8b24cd17df2 Module to spawn sub-commands in a platform-independent way.
Greg Ward <gward@python.net>
parents:
diff changeset
136 if exit_status == 0:
54522
5e4d070565e7 Merged revisions 73147 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 44542
diff changeset
137 return # hey, it succeeded!
11198
e8b24cd17df2 Module to spawn sub-commands in a platform-independent way.
Greg Ward <gward@python.net>
parents:
diff changeset
138 else:
43026
a6d3930b5613 General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents: 41480
diff changeset
139 raise DistutilsExecError(
a6d3930b5613 General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents: 41480
diff changeset
140 "command '%s' failed with exit status %d"
a6d3930b5613 General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents: 41480
diff changeset
141 % (cmd[0], exit_status))
14861
09c14ae5c2f5 Reformat docstrings.
Greg Ward <gward@python.net>
parents: 13803
diff changeset
142 elif os.WIFSTOPPED(status):
11198
e8b24cd17df2 Module to spawn sub-commands in a platform-independent way.
Greg Ward <gward@python.net>
parents:
diff changeset
143 continue
e8b24cd17df2 Module to spawn sub-commands in a platform-independent way.
Greg Ward <gward@python.net>
parents:
diff changeset
144 else:
43026
a6d3930b5613 General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents: 41480
diff changeset
145 raise DistutilsExecError(
a6d3930b5613 General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents: 41480
diff changeset
146 "unknown error executing '%s': termination status %d"
a6d3930b5613 General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents: 41480
diff changeset
147 % (cmd[0], status))
13803
e8b22bc88d95 Rene Liebscher: factor 'find_executable()' out of '_spawn_nt()'.
Greg Ward <gward@python.net>
parents: 12058
diff changeset
148
54522
5e4d070565e7 Merged revisions 73147 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 44542
diff changeset
149 def find_executable(executable, path=None):
5e4d070565e7 Merged revisions 73147 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 44542
diff changeset
150 """Tries to find 'executable' in the directories listed in 'path'.
13803
e8b22bc88d95 Rene Liebscher: factor 'find_executable()' out of '_spawn_nt()'.
Greg Ward <gward@python.net>
parents: 12058
diff changeset
151
54522
5e4d070565e7 Merged revisions 73147 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 44542
diff changeset
152 A string listing directories separated by 'os.pathsep'; defaults to
5e4d070565e7 Merged revisions 73147 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 44542
diff changeset
153 os.environ['PATH']. Returns the complete filename or None if not found.
13803
e8b22bc88d95 Rene Liebscher: factor 'find_executable()' out of '_spawn_nt()'.
Greg Ward <gward@python.net>
parents: 12058
diff changeset
154 """
e8b22bc88d95 Rene Liebscher: factor 'find_executable()' out of '_spawn_nt()'.
Greg Ward <gward@python.net>
parents: 12058
diff changeset
155 if path is None:
e8b22bc88d95 Rene Liebscher: factor 'find_executable()' out of '_spawn_nt()'.
Greg Ward <gward@python.net>
parents: 12058
diff changeset
156 path = os.environ['PATH']
54522
5e4d070565e7 Merged revisions 73147 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 44542
diff changeset
157
41480
99027c2b3fd2 Remove functions in string module that are also string methods. Also remove:
Neal Norwitz <nnorwitz@gmail.com>
parents: 40775
diff changeset
158 paths = path.split(os.pathsep)
54522
5e4d070565e7 Merged revisions 73147 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 44542
diff changeset
159 base, ext = os.path.splitext(executable)
5e4d070565e7 Merged revisions 73147 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 44542
diff changeset
160
79654
147b9d530dd0 Closes #16135: Removal of OS/2 support (distutils)
Jesus Cea <jcea@jcea.es>
parents: 71540
diff changeset
161 if (sys.platform == 'win32') and (ext != '.exe'):
13803
e8b22bc88d95 Rene Liebscher: factor 'find_executable()' out of '_spawn_nt()'.
Greg Ward <gward@python.net>
parents: 12058
diff changeset
162 executable = executable + '.exe'
54522
5e4d070565e7 Merged revisions 73147 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 44542
diff changeset
163
13803
e8b22bc88d95 Rene Liebscher: factor 'find_executable()' out of '_spawn_nt()'.
Greg Ward <gward@python.net>
parents: 12058
diff changeset
164 if not os.path.isfile(executable):
e8b22bc88d95 Rene Liebscher: factor 'find_executable()' out of '_spawn_nt()'.
Greg Ward <gward@python.net>
parents: 12058
diff changeset
165 for p in paths:
e8b22bc88d95 Rene Liebscher: factor 'find_executable()' out of '_spawn_nt()'.
Greg Ward <gward@python.net>
parents: 12058
diff changeset
166 f = os.path.join(p, executable)
e8b22bc88d95 Rene Liebscher: factor 'find_executable()' out of '_spawn_nt()'.
Greg Ward <gward@python.net>
parents: 12058
diff changeset
167 if os.path.isfile(f):
e8b22bc88d95 Rene Liebscher: factor 'find_executable()' out of '_spawn_nt()'.
Greg Ward <gward@python.net>
parents: 12058
diff changeset
168 # the file exists, we have a shot at spawn working
e8b22bc88d95 Rene Liebscher: factor 'find_executable()' out of '_spawn_nt()'.
Greg Ward <gward@python.net>
parents: 12058
diff changeset
169 return f
e8b22bc88d95 Rene Liebscher: factor 'find_executable()' out of '_spawn_nt()'.
Greg Ward <gward@python.net>
parents: 12058
diff changeset
170 return None
e8b22bc88d95 Rene Liebscher: factor 'find_executable()' out of '_spawn_nt()'.
Greg Ward <gward@python.net>
parents: 12058
diff changeset
171 else:
e8b22bc88d95 Rene Liebscher: factor 'find_executable()' out of '_spawn_nt()'.
Greg Ward <gward@python.net>
parents: 12058
diff changeset
172 return executable