ó É9Zc@`sìdZddlmZmZmZddgZddlZddlZddlZddl m Z m Z ddl m Z ddlmZdd lmZd „Zd „Zdid „Zd „Zd„Zd„Zddddd„Zddd„Zdd„Zd„Zddd„Zd„Zd„Zd„Z d„Z!d„Z"ej#dkraeZ$n*ej#d"kryeZ$ne%dej#ƒ‚e&d krèe$d!dƒe$d!dƒe d!dƒe d!dƒe!d!dƒe"d!dƒndS(#s/ exec_command Implements exec_command function that is (almost) equivalent to commands.getstatusoutput function but on NT, DOS systems the returned status is actually correct (though, the returned status values may be different by a factor). In addition, exec_command takes keyword arguments for (re-)defining environment variables. Provides functions: exec_command --- execute command in a specified directory and in the modified environment. find_executable --- locate a command using info from environment variable PATH. Equivalent to posix `which` command. Author: Pearu Peterson Created: 11 January 2003 Requires: Python 2.x Succesfully tested on: ======== ============ ================================================= os.name sys.platform comments ======== ============ ================================================= posix linux2 Debian (sid) Linux, Python 2.1.3+, 2.2.3+, 2.3.3 PyCrust 0.9.3, Idle 1.0.2 posix linux2 Red Hat 9 Linux, Python 2.1.3, 2.2.2, 2.3.2 posix sunos5 SunOS 5.9, Python 2.2, 2.3.2 posix darwin Darwin 7.2.0, Python 2.3 nt win32 Windows Me Python 2.3(EE), Idle 1.0, PyCrust 0.7.2 Python 2.1.1 Idle 0.8 nt win32 Windows 98, Python 2.1.1. Idle 0.8 nt win32 Cygwin 98-4.10, Python 2.1.1(MSC) - echo tests fail i.e. redefining environment variables may not work. FIXED: don't use cygwin echo! Comment: also `cmd /c echo` will not work but redefining environment variables do work. posix cygwin Cygwin 98-4.10, Python 2.3.3(cygming special) nt win32 Windows XP, Python 2.3.3 ======== ============ ================================================= Known bugs: * Tests, that send messages to stderr, fail when executed from MSYS prompt because the messages are lost at some point. i(tdivisiontabsolute_importtprint_functiont exec_commandtfind_executableN(t is_sequencetmake_temp_file(tlog(t get_exception(t open_latin1cC`stƒ\}}|jƒ|S(N(Rtclose(tfotname((sO/opt/alt/python27/lib64/python2.7/site-packages/numpy/distutils/exec_command.pyttemp_file_nameBs cC`sdtj}tjdkr`tjj|ƒ\}}|jƒjddƒ}tjj||ƒ}n|S(NtnttdostPYTHONWtPYTHON(RR( tsyst executabletosR tpathtsplittuppertreplacetjoin(t pythonexetfdirtfn((sO/opt/alt/python27/lib64/python2.7/site-packages/numpy/distutils/exec_command.pyt get_pythonexeGs cC`s||f}y ||SWntk r+nXtjd|ƒ|}|dkrjtjjdtjƒ}ntjdkrˆtj j }n d„}|j dƒr°|dd!}ndg}tjdkr tj j |ƒ\}}d d dg} |j ƒ| kr | }q ntj j|ƒr+dg} n1g|jtjƒD]} tj j| ƒ^q>} x¥| D]}tj j||ƒ}x|D]w} || } tj j| ƒs¶|| ƒ} ntj j| ƒr…tj| tjƒr…tjd| ƒ| ||<| Sq…WqcWtjd|ƒdS(sTReturn full path of a executable or None. Symbolic links are not followed. sfind_executable(%r)tPATHtposixcS`s|S(N((ta((sO/opt/alt/python27/lib64/python2.7/site-packages/numpy/distutils/exec_command.pytbst"iiÿÿÿÿtRRtos2s.exes.coms.batsFound executable %ssCould not locate executable %sN(RRR$(tKeyErrorRtdebugtNoneRtenvirontgettdefpathR Rtrealpatht startswithtsplitexttlowertisabsRtpathseptabspathRtislinktisfiletaccesstX_OKtinfotwarn(texeRt_cachetkeytorig_exeR+tsuffixesRtexttextra_suffixestpathstptstf_ext((sO/opt/alt/python27/lib64/python2.7/site-packages/numpy/distutils/exec_command.pyRPsF        1   '  cC`sBtjd|ƒi}x$|D]}tjj|ƒ|| %s ) 2>&1 | tee %s %ss( %s ; echo $? > %s ) > %s 2>&1sRunning os.system(%r)s&_exec_command_posix failed (status=%s)RTROiÿÿÿÿs (RR&RRR\R R'RtsystemR7RaR treadtintR tremove( RbRTRURDt command_strttmpfiletstsfiletfiltert command_posixtstatustft status_textttext((sO/opt/alt/python27/lib64/python2.7/site-packages/numpy/distutils/exec_command.pyR`ósF               c K`s£tjdƒtƒ}tƒ}tƒ}tƒ}t|dƒ}|jdƒ|jdƒ|jd|ƒ|jdƒ|jdƒ|jd|ƒ|jd tjƒ|jd |ƒ|jd |ƒ|jd |ƒ|jƒd ||f}tj |ƒ} | r"t d|fƒ‚ntj |ƒt |dƒ}t |jƒƒ} |jƒtj |ƒt |dƒ}|jƒ} |jƒtj |ƒ| | fS(Ns_exec_command_python(...)tws import os s import sys ssys.path.insert(0,%r) s&from exec_command import exec_command sdel sys.path[0] s cmd = %r sos.environ = %r s.s,o = exec_command(cmd, _with_python=0, **%r) s)f=open(%r,"w") f.write(str(s)) f.close() s$f=open(%r,"w") f.write(o) f.close() s%s %ss %r failedRO(RR&RR topentwriteRR(R Rkt RuntimeErrorRnR RmRl( RbRSRDt python_exetcmdfileRqtoutfileRutcmdRtRw((sO/opt/alt/python27/lib64/python2.7/site-packages/numpy/distutils/exec_command.pyR_(s>                cC`s(|ddkr$d|kr$d|S|S(NiR"Rjs"%s"((targ((sO/opt/alt/python27/lib64/python2.7/site-packages/numpy/distutils/exec_command.pyt quote_argPscK`sGtjdƒ|dkr+tjdk}n|dkrItjdk}nd}|r©tjjddƒ}t|ƒr—|ddjt |ƒƒg}qÎ|d|g}n%t|ƒr¿|}nt j |ƒ}t tdƒrétj }n„tj}t|dƒp |d|d3sN      3    W 4 ' Œ L 0