Current File : //proc/self/root/proc/self/root/lib64/python2.7/site-packages/numpy/distutils/exec_command.pyo
�
E�`Qc@s�dZddgZddlZddlZddlZddlmZmZddlm	Z	ddl
mZddlm
Z
d	�Zd
�Zd�Zdid�Zd
�Zd�Zd�Zddddd�Zddd�Zdd�Zd�Zddd�Zd�Zd�Zd�Zd�Zd�Zej dkrNeZ!n*ej d#krfeZ!ne"dej ��e#d kr�e!d!d"�e!d!d�ed!d"�ed!d�ed!d�ed!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 <pearu@cens.ioc.ee>
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(tis_sequencetmake_temp_file(tlog(t
get_exception(topen_latin1cCst�\}}|j�|S(N(Rtclose(tfotname((sB/usr/lib64/python2.7/site-packages/numpy/distutils/exec_command.pyttemp_file_name<s
cCsdtj}tjdkr`tjj|�\}}|j�jdd�}tjj||�}n|S(NtnttdostPYTHONWtPYTHON(sntR(	tsyst
executabletosR	tpathtsplittuppertreplacetjoin(t	pythonexetfdirtfn((sB/usr/lib64/python2.7/site-packages/numpy/distutils/exec_command.pyt
get_pythonexeAs	cCs)ddl}|jdt�tj|�S(Ni����s+splitcmdline is deprecated; use shlex.split(twarningstwarntDeprecationWarningtshlexR(tlineR((sB/usr/lib64/python2.7/site-packages/numpy/distutils/exec_command.pytsplitcmdlineJs	cCs||f}y||SWntk
r+nXtjd|�|}|dkrjtjjdtj�}ntjdkr�tj	j
}n	d�}|jd�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((sB/usr/lib64/python2.7/site-packages/numpy/distutils/exec_command.pyt<lambda>bst"ii����tRRtos2s.exes.coms.batsFound executable %ssCould not locate executable %sN(sntsdossos2(tKeyErrorRtdebugtNoneRtenvirontgettdefpathR	Rtrealpatht
startswithtsplitexttlowertisabsRtpathseptabspathRtislinktisfiletaccesstX_OKtgoodR(texeRt_cachetkeytorig_exeR.tsuffixesRtexttextra_suffixestpathstptstf_ext((sB/usr/lib64/python2.7/site-packages/numpy/distutils/exec_command.pyRPsF
		1


'
cCsBtjd|�i}x$|D]}tjj|�||<qW|S(Ns_preserve_environment(%r)(RR)RR+R,(tnamestenvR	((sB/usr/lib64/python2.7/site-packages/numpy/distutils/exec_command.pyt_preserve_environment�s

cKsAtjd�x-|j�D]\}}|p/dtj|<qWdS(Ns_update_environment(...)R&(RR)titemsRR+(RFR	tvalue((sB/usr/lib64/python2.7/site-packages/numpy/distutils/exec_command.pyt_update_environment�s
cCsCt|d�r;y|j�}tSWq?tk
r7tSXntSdS(sT
    Returns True if 'stream' supports the file descriptor and allows fileno().
    tfilenoN(thasattrRKtTruetIOErrortFalse(tstreamtr((sB/usr/lib64/python2.7/site-packages/numpy/distutils/exec_command.pyt_supports_fileno�s
R&ic	Ksbtjd|djg|j�D]}d|^q�f�|dkr[tjdk}n|dkrytjdk}ntjj|�}tjjtj	��}t
ddkr�tjjtjjt��}ngtjj
d�r�tjjd�}n@tjjtjd	�}tjj
|�r;tjj|�}n||krhtj|�tjd
|�ntjd|�t|j��}	t|�z�|r�ttj�r�tjj�dkr�t|d
||�}
nHtjdkrt|d|d||�}
nt|d|d||�}
Wd||krStj|�tjd|�nt|	�X|
S(s' Return (status,output) of executed command.

    command is a concatenated string of executable and arguments.
    The output contains both stdout and stderr messages.
    The following special keyword arguments can be used:
      use_shell - execute `sh -c command`
      use_tee   - pipe the output of command through tee
      execute_in - before run command `cd execute_in` and after `cd -`.

    On NT, DOS systems the returned status is correct for external commands.
    Wild cards will not work for non-posix systems or when use_shell=0.
    sexec_command(%r,%s)t,s%s=%rR"i�Rsexec_command.pyt.isNew cwd: %ssRetaining cwd: %si����texec_command_dirt	use_shelltuse_teeNsRestored cwd to %s(RR)RRHR*RR	RR4tgetcwdt__name__tdirnamet__file__R6RtargvtchdirRGtkeysRJRRtstdoutRKt_exec_command_pythont_exec_command_posixt
_exec_command(tcommandt
execute_inRVRWt_with_pythonRFtkvtoldcwdtexec_dirtoldenvtst((sB/usr/lib64/python2.7/site-packages/numpy/distutils/exec_command.pyR�sN1!


		
c
Ks�tjd�t|�r1djt|��}n|}t�}d}|r�t�}d}|dkrpd}nd||||f}nt�}d|||f}tjd|�tj|�}	|r�|	r�tj	d	|	�t
|d
||�Sn|dk	rEt|d�}
|
j�}t
|�}	|
j�tj|�nt|d�}
|
j�}|
j�tj|�|dd
kr�|d }n|	|fS(Ns_exec_command_posix(...)t R&is!| tr -cd "\n" | tr "\n" "."; echos&( %s ; echo $? > %s ) 2>&1 | tee %s %ss( %s ; echo $? > %s ) > %s 2>&1sRunning os.system(%r)s&_exec_command_posix failed (status=%s)RVRQi����s
(RR)RRtlistR
R*RtsystemRRbRtreadtintRtremove(
RcRVRWRFtcommand_strttmpfiletstsfiletfiltert
command_posixtstatustftstatus_textttext((sB/usr/lib64/python2.7/site-packages/numpy/distutils/exec_command.pyRa�sF
				



cKs�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
simport 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 failedRQ(RR)RR
topentwriteRR+RRmtRuntimeErrorRpRRoRn(RcRURFt
python_exetcmdfileRstoutfileRwtcmdRvRy((sB/usr/lib64/python2.7/site-packages/numpy/distutils/exec_command.pyR`s>
				









cCs(|ddkr$d|kr$d|S|S(NiR%Rks"%s"((targ((sB/usr/lib64/python2.7/site-packages/numpy/distutils/exec_command.pyt	quote_argDscKs�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<tjj|d�smtjd	|d�tjdkrmtjdd
g|}d}qmnttj�}ttj�}	tjj}
tjj}|r�tjj�}tj|�}
n|	r�tjj�}tj|�}nt�}t|d�}|r*t�}t|d�}ntjd|jtj|d|f�|d}|stt|�|d<n|
�|�|r�tj|j�|�n|	r�|r�tj|j�|�q�tj|j�|�ny|tj||tj�}WnDt k
rDt!t"��}d}tjj#d||df�nX|
�|�|rltj|
|�n|	r�tj||�n|j$�t%|d�}|j&�}|j$�tj'|�|r8|j$�t%|d�}|j&�}|j$�tj'|�|r8|r8|r#|d}n||}|GHq8n|ddkrU|d }n|dkrjd}n|rx|GHn||fS(Ns_exec_command(...)R"itSHELLs/bin/shs-cRktspawnvpesExecutable %s does not existRRtCOMSPECs/CiRzsRunning %s(%s,%r,%r,os.environ)i�s%s: %sRQs
i����(sntsdos((RR)R*RR	R+R,RRRlRRRLR�tspawnveRRR6RRRRR_tstderrtflushRKtdupR
R{RYtP_WAITR�tdup2tOSErrortstrRR|RRRnRp(RcRVRWRFt
using_commandtshR\t
spawn_commandt_so_has_filenot_se_has_filenotso_flushtse_flusht	so_filenotso_dupt	se_filenotse_dupR�tfoutterrfiletferrtargv0RvterrmessRy((sB/usr/lib64/python2.7/site-packages/numpy/distutils/exec_command.pyRbIs�
!
				

"









	cKsGt�}td�}|dk}|r�tjd�t|d�\}}t|ddd�\}}dtjd<t|d	�\}}t|d	dd
�\}}t|d	�\}}ntd�\}}td|�\}}td
|�\}}td|�\}}td|�\}}td|�\}}dGHdS(Ntechos7Using cygwin echo in win32 environment is not supporteds. -c "import os;print os.environ.get('AAA','')"s+ -c "import os;print os.environ.get('AAA')"tAAAtTeretHitBBBs. -c "import os;print os.environ.get('BBB','')"tHeysecho path=%path%s1%s -c "import sys;sys.stderr.write(sys.platform)"s%s -c "raise 'Ignore me.'"sT%s -c "import sys;sys.stderr.write('0');sys.stderr.write('1');sys.stderr.write('2')"s%s -c "import sys;sys.exit(15)"s%s -c "print 'Heipa'"tok(RRRRRRR+(tkwsRR�tusing_cygwin_echoRCto((sB/usr/lib64/python2.7/site-packages/numpy/distutils/exec_command.pyttest_nt�s8	

cKsHtd|�\}}td|�\}}tddd|�\}}td|�\}}dtjd<td|�\}}tddd	|�\}}td|�\}}td
|�\}}td|�\}}td|�\}}td
|�\}}td|�\}}td|�\}}td|�\}}dGHdS(Ns
echo Hellos	echo $AAAsecho "$AAA"R�R�R�R�secho "$BBB"R�tthis_is_not_a_commandsecho path=$PATHs3python -c "import sys,os;sys.stderr.write(os.name)"spython -c "raise 'Ignore me.'"sXpython -c "import sys;sys.stderr.write('0');sys.stderr.write('1');sys.stderr.write('2')"s#python -c "import sys;sys.exit(15)"spython -c "print 'Heipa'"R�(RRR+(R�RCR�((sB/usr/lib64/python2.7/site-packages/numpy/distutils/exec_command.pyt
test_posixs 
cKs�t�}t�}tjj|�}tjj|�}t|d�}|jd�|j�t	d||f|�\}}t	d||fd||�\}}tj
|�dGHdS(NRztHellos:%s -c "print 'Ignore the following IOError:',open(%r,'r')"s!%s -c "print open(%r,'r').read()"RdR�(RR
RRtbasenameRZR{R|RRRp(R�RRrRttmpdirRwRCR�((sB/usr/lib64/python2.7/site-packages/numpy/distutils/exec_command.pyttest_execute_in<s		


cKs$tddg|�\}}dGHdS(NtsvnRvssvn ok(R(R�RCR�((sB/usr/lib64/python2.7/site-packages/numpy/distutils/exec_command.pyttest_svnNscKs6tjdkr2tddg|�\}}dGHndS(NRtcls/Vscl ok(RR	R(R�RCR�((sB/usr/lib64/python2.7/site-packages/numpy/distutils/exec_command.pyttest_clSsR"RRsexec_command tests for t__main__RWi(sntsdos($t__doc__t__all__RRRtnumpy.distutils.misc_utilRRtnumpy.distutilsRtnumpy.distutils.compatRtnumpy.compatRR
RR R*RRGRJRRRRaR`R�RbR�R�R�R�R�R	ttesttNotImplementedErrorRY(((sB/usr/lib64/python2.7/site-packages/numpy/distutils/exec_command.pyt<module>.sN				3				J4'	w	L	0