Ignore:
Timestamp:
Mar 19, 2014, 11:31:01 PM (11 years ago)
Author:
dmik
Message:

python: Merge vendor 2.7.6 to trunk.

Location:
python/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • python/trunk

  • python/trunk/Lib/distutils/spawn.py

    r2 r391  
    77"""
    88
    9 # This module should be kept compatible with Python 2.1.
     9__revision__ = "$Id$"
    1010
    11 __revision__ = "$Id: spawn.py 37828 2004-11-10 22:23:15Z loewis $"
     11import sys
     12import os
    1213
    13 import sys, os, string
    14 from distutils.errors import *
     14from distutils.errors import DistutilsPlatformError, DistutilsExecError
    1515from distutils import log
    1616
    17 def spawn (cmd,
    18            search_path=1,
    19            verbose=0,
    20            dry_run=0):
     17def spawn(cmd, search_path=1, verbose=0, dry_run=0):
     18    """Run another program, specified as a command list 'cmd', in a new process.
    2119
    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.
    2421    cmd[0] is the program to run and cmd[1:] are the rest of its arguments.
    2522    There is no way to run a program with a name different from that of its
     
    4441              "don't know how to spawn programs on platform '%s'" % os.name
    4542
    46 # spawn ()
     43def _nt_quote_args(args):
     44    """Quote command-line arguments for DOS/Windows conventions.
    4745
    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
    5247    returns a new argument list.
    5348    """
    54 
    5549    # XXX this doesn't seem very robust to me -- but if the Windows guys
    5650    # say it'll work, I guess I'll have to accept it.  (What if an arg
     
    5852    # have to be escaped?  Is there an escaping mechanism other than
    5953    # 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
    6457    return args
    6558
    66 def _spawn_nt (cmd,
    67                search_path=1,
    68                verbose=0,
    69                dry_run=0):
    70 
     59def _spawn_nt(cmd, search_path=1, verbose=0, dry_run=0):
    7160    executable = cmd[0]
    7261    cmd = _nt_quote_args(cmd)
     
    7463        # either we find one or it stays the same
    7564        executable = find_executable(executable) or executable
    76     log.info(string.join([executable] + cmd[1:], ' '))
     65    log.info(' '.join([executable] + cmd[1:]))
    7766    if not dry_run:
    7867        # spawn for NT requires a full path to the .exe
     
    8877                  "command '%s' failed with exit status %d" % (cmd[0], rc)
    8978
    90 
    91 def _spawn_os2 (cmd,
    92                 search_path=1,
    93                 verbose=0,
    94                 dry_run=0):
    95 
     79def _spawn_os2(cmd, search_path=1, verbose=0, dry_run=0):
    9680    executable = cmd[0]
    97     #cmd = _nt_quote_args(cmd)
    9881    if search_path:
    9982        # either we find one or it stays the same
    10083        executable = find_executable(executable) or executable
    101     log.info(string.join([executable] + cmd[1:], ' '))
     84    log.info(' '.join([executable] + cmd[1:]))
    10285    if not dry_run:
    10386        # spawnv for OS/2 EMX requires a full path to the .exe
     
    11093        if rc != 0:
    11194            # 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))
    11396            raise DistutilsExecError, \
    11497                  "command '%s' failed with exit status %d" % (cmd[0], rc)
    11598
     99if sys.platform == 'darwin':
     100    from distutils import sysconfig
     101    _cfg_target = None
     102    _cfg_target_split = None
    116103
    117 def _spawn_posix (cmd,
    118                   search_path=1,
    119                   verbose=0,
    120                   dry_run=0):
    121 
    122     log.info(string.join(cmd, ' '))
     104def _spawn_posix(cmd, search_path=1, verbose=0, dry_run=0):
     105    log.info(' '.join(cmd))
    123106    if dry_run:
    124107        return
    125108    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)
    127131    pid = os.fork()
    128132
    129     if pid == 0:                        # in the child
     133    if pid == 0:  # in the child
    130134        try:
    131             #print "cmd[0] =", cmd[0]
    132             #print "cmd =", cmd
    133             exec_fn(cmd[0], cmd)
     135            exec_fn(*exec_args)
    134136        except OSError, e:
    135137            sys.stderr.write("unable to execute %s: %s\n" %
     
    139141        sys.stderr.write("unable to execute %s for unknown reasons" % cmd[0])
    140142        os._exit(1)
    141 
    142 
    143     else:                               # in the parent
     143    else:   # in the parent
    144144        # Loop until the child either exits or is terminated by a signal
    145145        # (ie. keep waiting if it's merely stopped)
    146146        while 1:
    147147            try:
    148                 (pid, status) = os.waitpid(pid, 0)
     148                pid, status = os.waitpid(pid, 0)
    149149            except OSError, exc:
    150150                import errno
     
    161161                exit_status = os.WEXITSTATUS(status)
    162162                if exit_status == 0:
    163                     return              # hey, it succeeded!
     163                    return   # hey, it succeeded!
    164164                else:
    165165                    raise DistutilsExecError, \
     
    174174                      "unknown error executing '%s': termination status %d" % \
    175175                      (cmd[0], status)
    176 # _spawn_posix ()
    177 
    178176
    179177def find_executable(executable, path=None):
    180     """Try to find 'executable' in the directories listed in 'path' (a
    181     string listing directories separated by 'os.pathsep'; defaults to
    182     os.environ['PATH']).  Returns the complete filename or None if not
    183     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.
    184182    """
    185183    if path is None:
    186184        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
    189188    if (sys.platform == 'win32' or os.name == 'os2') and (ext != '.exe'):
    190189        executable = executable + '.exe'
     190
    191191    if not os.path.isfile(executable):
    192192        for p in paths:
     
    198198    else:
    199199        return executable
    200 
    201 # find_executable()
Note: See TracChangeset for help on using the changeset viewer.