[Python-checkins] CVS: distutils/distutils spawn.py,1.8,1.9
Greg Ward
python-dev@python.org
Tue, 1 Aug 2000 18:08:04 -0700
Update of /cvsroot/python/distutils/distutils
In directory slayer.i.sourceforge.net:/tmp/cvs-serv10389
Modified Files:
spawn.py
Log Message:
Rene Liebscher: factor 'find_executable()' out of '_spawn_nt()'.
Index: spawn.py
===================================================================
RCS file: /cvsroot/python/distutils/distutils/spawn.py,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -r1.8 -r1.9
*** spawn.py 2000/03/26 21:47:00 1.8
--- spawn.py 2000/08/02 01:08:02 1.9
***************
*** 2,6 ****
Provides the 'spawn()' function, a front-end to various platform-
! specific functions for launching another program in a sub-process."""
# created 1999/07/24, Greg Ward
--- 2,8 ----
Provides the 'spawn()' function, a front-end to various platform-
! specific functions for launching another program in a sub-process.
! Also provides the 'find_executable()' to search the path for a given
! executable name. """
# created 1999/07/24, Greg Ward
***************
*** 66,80 ****
cmd = _nt_quote_args (cmd)
if search_path:
! paths = string.split( os.environ['PATH'], os.pathsep)
! base,ext = os.path.splitext(executable)
! if (ext != '.exe'):
! executable = executable + '.exe'
! if not os.path.isfile(executable):
! paths.reverse() # go over the paths and keep the last one
! for p in paths:
! f = os.path.join( p, executable )
! if os.path.isfile ( f ):
! # the file exists, we have a shot at spawn working
! executable = f
if verbose:
print string.join ([executable] + cmd[1:], ' ')
--- 68,73 ----
cmd = _nt_quote_args (cmd)
if search_path:
! # either we find one or it stays the same
! executable = find_executable(executable) or executable
if verbose:
print string.join ([executable] + cmd[1:], ' ')
***************
*** 92,96 ****
"command '%s' failed with exit status %d" % (cmd[0], rc)
-
def _spawn_posix (cmd,
--- 85,88 ----
***************
*** 148,149 ****
--- 140,166 ----
(cmd[0], status)
# _spawn_posix ()
+
+
+ def find_executable(executable, path=None):
+ """Try to find 'executable' in the directories listed in 'path' (a
+ string listing directories separated by 'os.pathsep'; defaults to
+ os.environ['PATH']). Returns the complete filename or None if not
+ found.
+ """
+ if path is None:
+ path = os.environ['PATH']
+ paths = string.split(path, os.pathsep)
+ (base, ext) = os.path.splitext(executable)
+ if (sys.platform == 'win32') and (ext != '.exe'):
+ executable = executable + '.exe'
+ if not os.path.isfile(executable):
+ for p in paths:
+ f = os.path.join(p, executable)
+ if os.path.isfile(f):
+ # the file exists, we have a shot at spawn working
+ return f
+ return None
+ else:
+ return executable
+
+ # find_executable()