
bc           @   s   d  Z  d Z d d l Z d d l Z d d l m Z m Z d d l m Z d d l	 m
 Z
 d d d d	  Z d
   Z d d d d  Z d d d d  Z e j d k r d d l	 m Z d a d a n  d d d d  Z d d  Z d S(   s   distutils.spawn

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.
s   $Id$iN(   t   DistutilsPlatformErrort   DistutilsExecError(   t   DEBUG(   t   logi   i    c         C   s   t  |   }  t j d k r1 t |  | d | nZ t j d k rV t |  | d | n5 t j d k r{ t |  | d | n t d t j  d S(   s  Run another program, specified as a command list 'cmd', in a new process.

    'cmd' is just the argument list for the new process, ie.
    cmd[0] is the program to run and cmd[1:] are the rest of its arguments.
    There is no way to run a program with a name different from that of its
    executable.

    If 'search_path' is true (the default), the system's executable
    search path will be used to find the program; otherwise, cmd[0]
    must be the exact path to the executable.  If 'dry_run' is true,
    the command will not actually be run.

    Raise DistutilsExecError if running the program fails in any way; just
    return on success.
    t   posixt   dry_runt   ntt   os2s1   don't know how to spawn programs on platform '%s'N(   t   listt   ost   namet   _spawn_posixt	   _spawn_ntt
   _spawn_os2R    (   t   cmdt   search_patht   verboseR   (    (    s%   /usr/lib/python2.7/distutils/spawn.pyt   spawn   s    c         C   s>   x7 t  |   D]) \ } } d | k r d | |  | <q q W|  S(   s   Quote command-line arguments for DOS/Windows conventions.

    Just wraps every argument which contains blanks in double quotes, and
    returns a new argument list.
    t    s   "%s"(   t	   enumerate(   t   argst   it   arg(    (    s%   /usr/lib/python2.7/distutils/spawn.pyt   _nt_quote_args/   s    c         C   s   |  d } t  |   }  | r1 t |  p+ | } n  t j d j | g |  d   | s y t j t j | |   } Wn9 t k
 r } t	 s | }  n  t
 d |  | d f  n X| d k r t	 s | }  n  t
 d |  | f  q n  d  S(   Ni    R   i   s   command %r failed: %sis%   command %r failed with exit status %d(   R   t   find_executableR   t   infot   joinR	   t   spawnvt   P_WAITt   OSErrorR   R   (   R   R   R   R   t
   executablet   rct   exc(    (    s%   /usr/lib/python2.7/distutils/spawn.pyR   ?   s$    
!		c         C   s   |  d } | r% t  |  p | } n  t j d j | g |  d   | s y t j t j | |   } Wn9 t k
 r } t s | }  n  t	 d |  | d f  n X| d k r t s | }  n  t j
 d |  | f  t	 d |  | f  q n  d  S(   Ni    R   i   s   command %r failed: %sis%   command %r failed with exit status %d(   R   R   R   R   R	   R   R   R   R   R   t   debug(   R   R   R   R   R   R   R    (    (    s%   /usr/lib/python2.7/distutils/spawn.pyR   W   s$    
!		t   darwin(   t	   sysconfigc         C   s_  t  j d j |    | r  d  S|  d } | r9 t j p? t j } d  } t j d k rGt	 d  k r t
 j d  pu d a	 t	 r g  t	 j d  D] } t |  ^ q a q n  t	 rGt j j d t	  } t g  | j d  D] } t |  ^ q k rd | t	 f }	 t |	   n  t t j d | } | r8t j p>t j } qGn  t j   }
 |
 d k ry0 | d  k r~| | |   n | | |  |  WnL t k
 r} t s| }  n  t j j d |  | j f  t j d	  n Xt s| }  n  t j j d
 |   t j d	  nJxGy t j |
 d  \ }
 } Wn] t k
 r} d d  l } | j | j k rfqn  t su| }  n  t d |  | d f  n Xt j  |  rt s| }  n  t d |  t j! |  f  qt j" |  r t j# |  } | d k rd  St s
| }  n  t d |  | f  qt j$ |  r5qqt sD| }  n  t d |  | f  qWd  S(   NR   i    R"   t   MACOSX_DEPLOYMENT_TARGETt    t   .sF   $MACOSX_DEPLOYMENT_TARGET mismatch: now "%s" but "%s" during configures   unable to execute %r: %s
i   s(   unable to execute %r for unknown reasonsis   command %r failed: %ss"   command %r terminated by signal %ds%   command %r failed with exit status %ds1   unknown error executing %r: termination status %d(%   R   R   R   R	   t   execvpt   execvt   Nonet   syst   platformt   _cfg_targetR#   t   get_config_vart   splitt   intt   _cfg_target_splitt   environt   getR    t   dictt   execvpet   execvet   forkR   R   t   stderrt   writet   strerrort   _exitt   waitpidt   errnot   EINTRR   t   WIFSIGNALEDt   WTERMSIGt	   WIFEXITEDt   WEXITSTATUSt
   WIFSTOPPED(   R   R   R   R   R   t   exec_fnt   envt   xt
   cur_targett   my_msgt   pidt   et   statusR    R<   t   exit_status(    (    s%   /usr/lib/python2.7/distutils/spawn.pyR   t   s    
..							c         C   s   | d k r' t j j d t j  } n  | j t j  } t j j |   \ } } t	 j
 d k so t j d k r | d k r |  d }  n  t j j |   s x9 | D]1 } t j j | |   } t j j |  r | Sq Wd S|  Sd S(   s   Tries 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.
    t   PATHt   win32R   s   .exeN(   R)   R	   R1   R2   t   defpathR.   t   pathsept   patht   splitextR*   R+   R
   t   isfileR   (   R   RP   t   pathst   baset   extt   pt   f(    (    s%   /usr/lib/python2.7/distutils/spawn.pyR      s    *(   t   __doc__t   __revision__R*   R	   t   distutils.errorsR    R   t   distutils.debugR   t	   distutilsR   R   R   R   R   R+   R#   R)   R,   R0   R   R   (    (    (    s%   /usr/lib/python2.7/distutils/spawn.pyt   <module>   s    		X