ó °¿v]c@`sdZddlmZmZmZddgZddlZddlZddlZddl Z ddl m Z m Z ddl mZd„Zd „Zd „Zd „Zdid „Zd „Zd„Zd„Zddddd„Zddd„Zd„ZdS(s0 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 Successfully 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(tlogcC`s“tjtƒ}|d kr$d}n|j|ddƒ}|jddƒ}|ddkrh|d }ntjd kr|jdddƒ}n|S( sŸ Convert `bytes` in the encoding used by a subprocess into a filesystem-appropriate `str`. Inherited from `exec_command`, and possibly incorrect. tasciiterrorstreplaces s iÿÿÿÿiiN(ii( tlocaletgetpreferredencodingtFalsetNonetdecodeR tsyst version_infotencode(toutputtmylocale((sl/home/ec2-user/environment/lambda-staging/venv/lib64/python2.7/dist-packages/numpy/distutils/exec_command.pytfilepath_from_subprocess_output@s   cC`s¤tjjdkr%tjj|ƒn{ttjdƒrMtjjj|ƒnSttjdƒrtjj|jtjjƒƒntjj|jdddƒƒdS(sÈ Forward bytes from a subprocess call to the console, without attempting to decode them. The assumption is that the subprocess call already returned bytes in a suitable encoding. itbuffertencodingtutf8R R N( RRtmajortstdouttwritethasattrRRR(tval((sl/home/ec2-user/environment/lambda-staging/venv/lib64/python2.7/dist-packages/numpy/distutils/exec_command.pytforward_bytes_to_stdoutUs"cC`stƒ\}}|jƒ|S(N(Rtclose(tfotname((sl/home/ec2-user/environment/lambda-staging/venv/lib64/python2.7/dist-packages/numpy/distutils/exec_command.pyttemp_file_nameks cC`s‰tj}tjdkr…tjj|ƒ\}}|jƒjddƒ}tjj||ƒ}tjj |ƒs…t d|fƒ‚n|S(NtnttdostPYTHONWtPYTHONs%r is not a file(R#R$( Rt executabletosR!tpathtsplittupperR tjointisfiletAssertionError(t pythonexetfdirtfn((sl/home/ec2-user/environment/lambda-staging/venv/lib64/python2.7/dist-packages/numpy/distutils/exec_command.pyt get_pythonexeps (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((sl/home/ec2-user/environment/lambda-staging/venv/lib64/python2.7/dist-packages/numpy/distutils/exec_command.pyt‹tt"iiÿÿÿÿR7R#R$tos2s.exes.coms.batsFound executable %ssCould not locate executable %sN(R#R$R9(tKeyErrorRtdebugRR(tenvirontgettdefpathR!R)trealpatht startswithtsplitexttlowertisabsR*tpathseptabspathR,tislinkR-taccesstX_OKtinfotwarn(texeR)t_cachetkeytorig_exeR?tsuffixesR1texttextra_suffixestpathstptstf_ext((sl/home/ec2-user/environment/lambda-staging/venv/lib64/python2.7/dist-packages/numpy/distutils/exec_command.pyRysF        1   '  cC`s%tjd|ƒd„|Dƒ}|S(Ns_preserve_environment(%r)cS`s%i|]}tjj|ƒ|“qS((R(R<R=(t.0R!((sl/home/ec2-user/environment/lambda-staging/venv/lib64/python2.7/dist-packages/numpy/distutils/exec_command.pys ®s (RR;(tnamestenv((sl/home/ec2-user/environment/lambda-staging/venv/lib64/python2.7/dist-packages/numpy/distutils/exec_command.pyt_preserve_environment¬scK`sAtjdƒx-|jƒD]\}}|p/dtj| 1  !        c K`sû|dkrtjdk}n|dkr<tjdk}ntjdkr¥|r¥tjjddƒ}t|ƒr|ddj|ƒg}n|d|g}t}n7tjdkrÜt|ƒrÜdjd„|Dƒƒ}n|påd}y7tj |d|d |d tj d tj d tƒ}Wnt k r3dSX|j ƒ\}}tjtƒ}|dkrjd}n|j|ddƒ}|jddƒ}|ddkr®|d }ntjdkrÕ|jdddƒ}n|rî|rît|ƒn|j|fS(s0 Internal workhorse for exec_command(). R4tSHELLs/bin/shs-ct R#cs`s|]}t|ƒVqdS(N(t _quote_arg(RVtarg((sl/home/ec2-user/environment/lambda-staging/venv/lib64/python2.7/dist-packages/numpy/distutils/exec_command.pys stshellRXRtstderrtuniversal_newlinesiR7RR R s s iÿÿÿÿiiN(iR7(ii(RR(R!R<R=RR,R t subprocesstPopentPIPEtSTDOUTtEnvironmentErrort communicateR R RR RRRtprintt returncode( RoRdReRXtshtprocttextterrR((sl/home/ec2-user/environment/lambda-staging/venv/lib64/python2.7/dist-packages/numpy/distutils/exec_command.pyRn sB              cC`s$d|kr d|kr d|S|S(sB Quote the argument for safe use in a shell command line. R8Rxs"%s"((Rz((sl/home/ec2-user/environment/lambda-staging/venv/lib64/python2.7/dist-packages/numpy/distutils/exec_command.pyRyCs(t__doc__t __future__RRRt__all__R(RR~R tnumpy.distutils.misc_utilRRtnumpy.distutilsRRRR"R2RRRYR\RaRRnRy(((sl/home/ec2-user/environment/lambda-staging/venv/lib64/python2.7/dist-packages/numpy/distutils/exec_command.pyt3s(         3    E: