ó ‡Uc@s®dZddgZddlZddlZddlZddlmZmZddlm Z d„Z d„Z d „Z did „Zd „Zd „Zd dddd„Zddd„Zd d„Zd„Zddd„Zd„Zd„Zd„Zd„Zd„Zejdkr%eZn(ejd kr=eZnedej‚edkrªeddƒeddƒeddƒeddƒeddƒeddƒ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. t exec_commandtfind_executableiÿÿÿÿN(t is_sequencetmake_temp_file(tlogcCstƒ\}}|jƒ|S(N(Rtclose(tfotname((s@/usr/lib/python2.7/site-packages/numpy/distutils/exec_command.pyttemp_file_name9s cCs‰tj}tjdkr…tjj|ƒ\}}|jƒjddƒ}tjj||ƒ}tjj |ƒs…t d|fƒ‚n|S(NtnttdostPYTHONWtPYTHONs%r is not a file(sntsdos( tsyst executabletosRtpathtsplittuppertreplacetjointisfiletAssertionError(t pythonexetfdirtfn((s@/usr/lib/python2.7/site-packages/numpy/distutils/exec_command.pyt get_pythonexe>s (cCs)ddl}|jdtƒtj|ƒS(Niÿÿÿÿs+splitcmdline is deprecated; use shlex.split(twarningstwarntDeprecationWarningtshlexR(tlineR((s@/usr/lib/python2.7/site-packages/numpy/distutils/exec_command.pyt splitcmdlineGs  cCs||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)tPATHtposixcSs|S(N((ta((s@/usr/lib/python2.7/site-packages/numpy/distutils/exec_command.pyt_st"iiÿÿÿÿtR R tos2s.exes.coms.batsFound executable %ssCould not locate executable %sN(sntsdossos2(tKeyErrorRtdebugtNoneRtenvirontgettdefpathRRtrealpatht startswithtsplitexttlowertisabsRtpathseptabspathRtislinkRtaccesstX_OKtgoodR(texeRt_cachetkeytorig_exeR.tsuffixesRtexttextra_suffixestpathstptstf_ext((s@/usr/lib/python2.7/site-packages/numpy/distutils/exec_command.pyRMsF        1   '  cCsBtjd|ƒ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)RMtriÿÿÿÿs (RR)RRtlistRR*RtsystemRRZtopentreadtintRtremove( R[RMRNREt command_strttmpfiletstsfiletfiltert command_posixtstatustft status_textttext((s@/usr/lib/python2.7/site-packages/numpy/distutils/exec_command.pyRYÖsF               c Ks£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 failedRd(RR)RRRgtwriteRR+RRft RuntimeErrorRjRiRh( R[RLREt python_exetcmdfileRmtoutfileRqtcmdRpRs((s@/usr/lib/python2.7/site-packages/numpy/distutils/exec_command.pyRX s>                cCs(|ddkr$d|kr$d|S|S(NiR%Rcs"%s"((targ((s@/usr/lib/python2.7/site-packages/numpy/distutils/exec_command.pyt quote_arg3scKs!tjdƒ|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ƒ‚dGHdS(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¡RBR£((s@/usr/lib/python2.7/site-packages/numpy/distutils/exec_command.pyt test_posixós<**** ******$***cKstƒ}tƒ}tjj|ƒ}tjj|ƒ}t|dƒ}|jdƒ|jƒt d||f|\}}|r|dksŸt ||fƒ‚t d||fd||\}}|dkrÜ|dksît ||fƒ‚tj |ƒdGHdS( NRtR¥s:%s -c "print 'Ignore the following IOError:',open(%r,'r')"R&s!%s -c "print open(%r,'r').read()"R\iR ( RRRRtbasenameRQRgRuRRRRj(R¡RRlRttmpdirRqRBR£((s@/usr/lib/python2.7/site-packages/numpy/distutils/exec_command.pyttest_execute_in#s    $* cKs<tddg|\}}|s3t||fƒ‚dGHdS(NtsvnRpssvn ok(RR(R¡RBR£((s@/usr/lib/python2.7/site-packages/numpy/distutils/exec_command.pyttest_svn5scKsNtjdkrJtddg|\}}|sBt||fƒ‚dGHndS(NR tcls/Vscl ok(RRRR(R¡RBR£((s@/usr/lib/python2.7/site-packages/numpy/distutils/exec_command.pyttest_cl:sR"R R sexec_command tests for t__main__RNi(sntsdos(t__doc__t__all__RR Rtnumpy.distutils.misc_utilRRtnumpy.distutilsRRRR R*RRFRIRRYRXR|RZR¤R§RªR¬R®RttesttNotImplementedErrorRP(((s@/usr/lib/python2.7/site-packages/numpy/distutils/exec_command.pyt.sH      3    I 4 ' o L 0