
$8Zc        	   @   s   d  Z  d Z d d k Z d d k Z d d k Z d d k Td d k l Z d d d d  Z d	   Z	 d d d d
  Z
 d d d d  Z 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   *(   t   logi   i    c         C   s   t  i d j o t |  | d | n_ t  i d j o t |  | d | n8 t  i d j o t |  | d | n t d t  i  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   ost   namet   _spawn_posixt	   _spawn_ntt
   _spawn_os2t   DistutilsPlatformError(   t   cmdt   search_patht   verboseR   (    (    s%   /usr/lib/python2.6/distutils/spawn.pyt   spawn   s    c         C   sT   xM t  t |    D]9 } t i |  | d  d j o 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    is   "%s"(   t   ranget   lent   stringt   find(   t   argst   i(    (    s%   /usr/lib/python2.6/distutils/spawn.pyt   _nt_quote_args1   s
     c         C   s   |  d } t  |   }  | o t |  p | } n t i t i | g |  d d   | p{ y t i t i | |   } Wn0 t	 j
 o$ } t
 d |  d | d f  n X| d j o t
 d |  d | f  q n d  S(   Ni    i   R   s   command '%s' failed: %sis'   command '%s' failed with exit status %d(   R   t   find_executableR   t   infoR   t   joinR   t   spawnvt   P_WAITt   OSErrort   DistutilsExecError(   R   R   R   R   t
   executablet   rct   exc(    (    s%   /usr/lib/python2.6/distutils/spawn.pyR	   B   s    
$c         C   s   |  d } | o t  |  p | } n t i t i | g |  d d   | p y t i t i | |   } Wn0 t j
 o$ } t	 d |  d | d f  n X| d j o. d |  d | f GHt	 d |  d | f  q n d  S(   Ni    i   R   s   command '%s' failed: %sis'   command '%s' failed with exit status %d(
   R   R   R   R   R   R   R   R   R   R   (   R   R   R   R   R   R    R!   (    (    s%   /usr/lib/python2.6/distutils/spawn.pyR
   [   s    
$c         C   s	  t  i t i |  d   | o d  S| o
 t i p t i } t i   } | d j o y | |  d |   WnC t j
 o7 } t	 i
 i d |  d | i f  t i d  n Xt	 i
 i d |  d  t i d  n*x&y t i | d  \ } } WnV t j
 oJ } d d  k }	 | i |	 i j o q n t d |  d | d f  n Xt i |  o$ t d |  d t i |  f  q t i |  o< t i |  }
 |
 d j o d  St d	 |  d |
 f  q t i |  o q q t d
 |  d | f  q d  S(   NR   i    s   unable to execute %s: %s
i   s(   unable to execute %s for unknown reasonsis   command '%s' failed: %ss$   command '%s' terminated by signal %ds'   command '%s' failed with exit status %ds3   unknown error executing '%s': termination status %d(   R   R   R   R   R   t   execvpt   execvt   forkR   t   syst   stderrt   writet   strerrort   _exitt   waitpidt   errnot   EINTRR   t   WIFSIGNALEDt   WTERMSIGt	   WIFEXITEDt   WEXITSTATUSt
   WIFSTOPPED(   R   R   R   R   t   exec_fnt   pidt   et   statusR!   R+   t   exit_status(    (    s%   /usr/lib/python2.6/distutils/spawn.pyR   u   sN    c         C   s   | d j o t i d } n t i | t i  } t i i |   \ } } t i	 d j p t i
 d j o | d j o |  d }  n t i i |   pC x; | D]3 } t i i | |   } t i i |  o | Sq Wd S|  Sd S(   s   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.
    t   PATHt   win32R   s   .exeN(   t   NoneR   t   environR   t   splitt   pathsept   patht   splitextR%   t   platformR   t   isfileR   (   R   R=   t   pathst   baset   extt   pt   f(    (    s%   /usr/lib/python2.6/distutils/spawn.pyR      s    - 	(   t   __doc__t   __revision__R%   R   R   t   distutils.errorst	   distutilsR   R   R   R	   R
   R   R9   R   (    (    (    s%   /usr/lib/python2.6/distutils/spawn.pyt   <module>   s$   $
	;