<s> """<STR_LIT>""" <EOL> __revision__ = "<STR_LIT>" <EOL> import sys <EOL> import os <EOL> from distutils . errors import DistutilsPlatformError , DistutilsExecError <EOL> from distutils . debug import DEBUG <EOL> from distutils import log <EOL> def spawn ( cmd , search_path = <NUM_LIT:1> , verbose = <NUM_LIT:0> , dry_run = <NUM_LIT:0> ) : <EOL> """<STR_LIT>""" <EOL> cmd = list ( cmd ) <EOL> if os . name == '<STR_LIT>' : <EOL> _spawn_posix ( cmd , search_path , dry_run = dry_run ) <EOL> elif os . name == '<STR_LIT>' : <EOL> _spawn_nt ( cmd , search_path , dry_run = dry_run ) <EOL> elif os . name == '<STR_LIT>' : <EOL> _spawn_os2 ( cmd , search_path , dry_run = dry_run ) <EOL> else : <EOL> raise DistutilsPlatformError , "<STR_LIT>" % os . name <EOL> def _nt_quote_args ( args ) : <EOL> """<STR_LIT>""" <EOL> for i , arg in enumerate ( args ) : <EOL> if '<STR_LIT:U+0020>' in arg : <EOL> args [ i ] = '<STR_LIT>' % arg <EOL> return args <EOL> def _spawn_nt ( cmd , search_path = <NUM_LIT:1> , verbose = <NUM_LIT:0> , dry_run = <NUM_LIT:0> ) : <EOL> executable = cmd [ <NUM_LIT:0> ] <EOL> cmd = _nt_quote_args ( cmd ) <EOL> if search_path : <EOL> executable = find_executable ( executable ) or executable <EOL> log . info ( '<STR_LIT:U+0020>' . join ( [ executable ] + cmd [ <NUM_LIT:1> : ] ) ) <EOL> if not dry_run : <EOL> try : <EOL> rc = os . spawnv ( os . P_WAIT , executable , cmd ) <EOL> except OSError , exc : <EOL> if not DEBUG : <EOL> cmd = executable <EOL> raise DistutilsExecError , "<STR_LIT>" % ( cmd , exc [ - <NUM_LIT:1> ] ) <EOL> if rc != <NUM_LIT:0> : <EOL> if not DEBUG : <EOL> cmd = executable <EOL> raise DistutilsExecError , "<STR_LIT>" % ( cmd , rc ) <EOL> def _spawn_os2 ( cmd , search_path = <NUM_LIT:1> , verbose = <NUM_LIT:0> , dry_run = <NUM_LIT:0> ) : <EOL> executable = cmd [ <NUM_LIT:0> ] <EOL> if search_path : <EOL> executable = find_executable ( executable ) or executable <EOL> log . info ( '<STR_LIT:U+0020>' . join ( [ executable ] + cmd [ <NUM_LIT:1> : ] ) ) <EOL> if not dry_run : <EOL> try : <EOL> rc = os . spawnv ( os . P_WAIT , executable , cmd ) <EOL> except OSError , exc : <EOL> if not DEBUG : <EOL> cmd = executable <EOL> raise DistutilsExecError , "<STR_LIT>" % ( cmd , exc [ - <NUM_LIT:1> ] ) <EOL> if rc != <NUM_LIT:0> : <EOL> if not DEBUG : <EOL> cmd = executable <EOL> log . debug ( "<STR_LIT>" % ( cmd , rc ) ) <EOL> raise DistutilsExecError , "<STR_LIT>" % ( cmd , rc ) <EOL> if sys . platform == '<STR_LIT>' : <EOL> from distutils import sysconfig <EOL> _cfg_target = None <EOL> _cfg_target_split = None <EOL> def _spawn_posix ( cmd , search_path = <NUM_LIT:1> , verbose = <NUM_LIT:0> , dry_run = <NUM_LIT:0> ) : <EOL> log . info ( '<STR_LIT:U+0020>' . join ( cmd ) ) <EOL> if dry_run : <EOL> return <EOL> executable = cmd [ <NUM_LIT:0> ] <EOL> exec_fn = search_path and os . execvp or os . execv <EOL> env = None <EOL> if sys . platform == '<STR_LIT>' : <EOL> global _cfg_target , _cfg_target_split <EOL> if _cfg_target is None : <EOL> _cfg_target = sysconfig . get_config_var ( <EOL> '<STR_LIT>' ) or '<STR_LIT>' <EOL> if _cfg_target : <EOL> _cfg_target_split = [ int ( x ) for x in _cfg_target . split ( '<STR_LIT:.>' ) ] <EOL> if _cfg_target : <EOL> cur_target = os . environ . get ( '<STR_LIT>' , _cfg_target ) <EOL> if _cfg_target_split > [ int ( x ) for x in cur_target . split ( '<STR_LIT:.>' ) ] : <EOL> my_msg = ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> % ( cur_target , _cfg_target ) ) <EOL> raise DistutilsPlatformError ( my_msg ) <EOL> env = dict ( os . environ , <EOL> MACOSX_DEPLOYMENT_TARGET = cur_target ) <EOL> exec_fn = search_path and os . execvpe or os . execve <EOL> pid = os . fork ( ) <EOL> if pid == <NUM_LIT:0> : <EOL> try : <EOL> if env is None : <EOL> exec_fn ( executable , cmd ) <EOL> else : <EOL> exec_fn ( executable , cmd , env ) <EOL> except OSError , e : <EOL> if not DEBUG : <EOL> cmd = executable <EOL> sys . stderr . write ( "<STR_LIT>" % <EOL> ( cmd , e . strerror ) ) <EOL> os . _exit ( <NUM_LIT:1> ) <EOL> if not DEBUG : <EOL> cmd = executable <EOL> sys . stderr . write ( "<STR_LIT>" % cmd ) <EOL> os . _exit ( <NUM_LIT:1> ) <EOL> else : <EOL> while <NUM_LIT:1> : <EOL> try : <EOL> pid , status = os . waitpid ( pid , <NUM_LIT:0> ) <EOL> except OSError , exc : <EOL> import errno <EOL> if exc . errno == errno . EINTR : <EOL> continue <EOL> if not DEBUG : <EOL> cmd = executable <EOL> raise DistutilsExecError , "<STR_LIT>" % ( cmd , exc [ - <NUM_LIT:1> ] ) <EOL> if os . WIFSIGNALED ( status ) : <EOL> if not DEBUG : <EOL> cmd = executable <EOL> raise DistutilsExecError , "<STR_LIT>" % ( cmd , os . WTERMSIG ( status ) ) <EOL> elif os . WIFEXITED ( status ) : <EOL> exit_status = os . WEXITSTATUS ( status ) <EOL> if exit_status == <NUM_LIT:0> : <EOL> return <EOL> else : <EOL> if not DEBUG : <EOL> cmd = executable <EOL> raise DistutilsExecError , "<STR_LIT>" % ( cmd , exit_status ) <EOL> elif os . WIFSTOPPED ( status ) : <EOL> continue <EOL> else : <EOL> if not DEBUG : <EOL> cmd = executable <EOL> raise DistutilsExecError , "<STR_LIT>" % ( cmd , status ) <EOL> def find_executable ( executable , path = None ) : <EOL> """<STR_LIT>""" <EOL> if path is None : <EOL> path = os . environ [ '<STR_LIT>' ] <EOL> paths = path . split ( os . pathsep ) <EOL> base , ext = os . path . splitext ( executable ) <EOL> if ( sys . platform == '<STR_LIT:win32>' or os . name == '<STR_LIT>' ) and ( ext != '<STR_LIT>' ) : <EOL> executable = executable + '<STR_LIT>' <EOL> if not os . path . isfile ( executable ) : <EOL> for p in paths : <EOL> f = os . path . join ( p , executable ) <EOL> if os . path . isfile ( f ) : <EOL> return f <EOL> return None <EOL> else : <EOL> return executable </s>
