ó É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`s‰tj}tjdkr…tjj|ƒ\}}|jƒjddƒ}tjj||ƒ}tjj |ƒs…t d|fƒ‚n|S(NtnttdostPYTHONWtPYTHONs%r is not a file(RR( tsyst executabletosR tpathtsplittuppertreplacetjointisfiletAssertionError(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 startswithtsplitexttlowertisabsRtpathseptabspathRtislinkRtaccesstX_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)RURPiÿÿÿÿs (RR(RRR]R R)RtsystemR8RbR treadtintR tremove( RcRURVREt command_strttmpfiletstsfiletfiltert command_posixtstatustft status_textttext((sO/opt/alt/python27/lib64/python2.7/site-packages/numpy/distutils/exec_command.pyRaó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 failedRP(RR(RR topentwriteRR*R Rlt RuntimeErrorRoR RnRm( RcRTREt python_exetcmdfileRrtoutfileRvtcmdRuRx((sO/opt/alt/python27/lib64/python2.7/site-packages/numpy/distutils/exec_command.pyR`(s>                cC`s(|ddkr$d|kr$d|S|S(NiR$Rks"%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|d|dksPt||fƒ‚td|\}}|dkr}|dkst||fƒ‚td|\}}|dkr¶|sÈt||fƒ‚td|\}}|dkrõ|dkst||fƒ‚td|\}}|dkr4|dksFt||fƒ‚td|\}}|dkrs|dks…t||fƒ‚tdƒdS(Ns echo HelloitHellos echo $AAAR%s echo "$AAA"R¨R©RªR«s echo "$BBB"R¬tthis_is_not_a_commandsecho path=$PATHs3python -c "import sys,os;sys.stderr.write(os.name)"R!spython -c "raise 'Ignore me.'"isXpython -c "import sys;sys.stderr.write('0');sys.stderr.write('1');sys.stderr.write('2')"R®s#python -c "import sys;sys.exit(15)"ispython -c "print 'Heipa'"R¯R°(RRRR*R“(R±RBR³((sO/opt/alt/python27/lib64/python2.7/site-packages/numpy/distutils/exec_command.pyt test_posix-s<**** ******$***cK`s tƒ}tƒ}tjj|ƒ}tjj|ƒ}t|dƒ}|jdƒ|jƒt d||f|\}}|r|dksŸt ||fƒ‚t d||fd||\}}|dkrÜ|dksît ||fƒ‚tj |ƒt dƒdS( NRyRµs:%s -c "print 'Ignore the following IOError:',open(%r,'r')"R%s!%s -c "print open(%r,'r').read()"RdiR°( RR RRtbasenameRYRzR{R RRRoR“(R±RRqRttmpdirRvRBR³((sO/opt/alt/python27/lib64/python2.7/site-packages/numpy/distutils/exec_command.pyttest_execute_in]s    $* cK`sAtddg|\}}|s3t||fƒ‚tdƒdS(NtsvnRussvn ok(RRR“(R±RBR³((sO/opt/alt/python27/lib64/python2.7/site-packages/numpy/distutils/exec_command.pyttest_svnoscK`sStjdkrOtddg|\}}|sBt||fƒ‚tdƒndS(NRtcls/Vscl ok(RR RRR“(R±RBR³((sO/opt/alt/python27/lib64/python2.7/site-packages/numpy/distutils/exec_command.pyttest_cltsR!RRsexec_command tests for t__main__RV(RR('t__doc__t __future__RRRt__all__RRR†tnumpy.distutils.misc_utilRRtnumpy.distutilsRtnumpy.distutils.compatRt numpy.compatR R RR)RRFRIRQRRaR`R‚RbR´R·RºR¼R¾R ttesttNotImplementedErrorRX(((sO/opt/alt/python27/lib64/python2.7/site-packages/numpy/distutils/exec_command.pyt3sN      3    W 4 ' Œ L 0