%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /usr/lib/python2.7/site-packages/salt/utils/
Upload File :
Create Path :
Current File : //usr/lib/python2.7/site-packages/salt/utils/nb_popen.pyc

�
���^c@@sdZddlmZmZmZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZej
dkZy6ddlmZmZddlmZddlZWnek
r�ddlZnXe
je�Zdejfd��YZdS(	u
    :codeauthor: Pedro Algarvio (pedro@algarvio.me)


    salt.utils.nb_popen
    ~~~~~~~~~~~~~~~~~~~

    Non blocking subprocess Popen.

    This functionality has been adapted to work on windows following the recipe
    found on:

        http://code.activestate.com/recipes/440554/
i(tabsolute_importtunicode_literalstprint_functionNuwin32(tReadFilet	WriteFile(t
PeekNamedPipetNonBlockingPopencB@s�eZdZdZd�Zdd�Zdd�Zddd�Zd�Z	d�Z
erod	�Zd
�Z
nd�Zd�Z
d
d�Zdd�ZRS(u$salt.utils.nb_popen.STDOUT.PID-{pid}u$salt.utils.nb_popen.STDERR.PID-{pid}cO@s_|jdt�|_|jdd�|_|jd|j�|_|jd|j�|_|jdd�}|jdd�}tt	|�j
||�tj|j�|_
tj|jjd|j��|_|tjkr�|j
|_|j|_n9tj|j�|_tj|jjd|j��|_tjd	|j|dkrT|n|�dS(
Nustream_stdsumax_size_in_memi�ustdout_logger_nameustderr_logger_nameulogging_commandustderrtpidu"Running command under pid %s: '%s'(tpoptFalsetstream_stdstmax_size_in_memt_stdout_logger_name_t_stderr_logger_name_tNonetgettsuperRt__init__ttempfiletSpooledTemporaryFiletstdout_bufftloggingt	getLoggertformatRt_stdout_loggert
subprocesstSTDOUTtstderr_bufft_stderr_loggertlogtinfo(tselftargstkwargstlogging_commandtstderr((s7/usr/lib/python2.7/site-packages/salt/utils/nb_popen.pyR.s.cC@s|jd|�S(Nustdout(t_recv(Rtmaxsize((s7/usr/lib/python2.7/site-packages/salt/utils/nb_popen.pytrecv_scC@s|jd|�S(Nustderr(R$(RR%((s7/usr/lib/python2.7/site-packages/salt/utils/nb_popen.pytrecv_errbsucC@s(|j|�|j|�|j|�fS(N(tsendR&R'(RtinputR%((s7/usr/lib/python2.7/site-packages/salt/utils/nb_popen.pyt	send_recvescC@s=|dkrd}n|dkr*d}nt||�|fS(Nii(Rtgetattr(RtwhichR%((s7/usr/lib/python2.7/site-packages/salt/utils/nb_popen.pytget_conn_maxsizehs
		cC@s't||�j�t||d�dS(N(R+tclosetsetattrR(RR,((s7/usr/lib/python2.7/site-packages/salt/utils/nb_popen.pyt_closeoscC@s�|js
dSy1tj|jj��}t||�\}}Wnetk
r[|jd�Stj	j
tfk
r�}|jddt
jfkr�|jd�S�nX|S(Nustdiniim(tstdinRtmsvcrtt
get_osfhandletfilenoRt
ValueErrorR0Rt
pywintypesterrort	ExceptionR terrnot	ESHUTDOWN(RR)txterrCodetwrittentwhy((s7/usr/lib/python2.7/site-packages/salt/utils/nb_popen.pyR(ts	


c
C@s�|j||�\}}|dkr(dSymtj|j��}t|d�\}}}||krm|}n|dkr�t||d�\}}nWnetk
r�|j|�St	j
jtfk
r�}	|	j
ddtjfkr�|j|�S�nXt|dj|��j|�t|dj|��j|j��|jrctt|�j|�n|jr~|j|�}n|S(Niimu{0}_buffu_{0}_logger(R-RR2R3R4RRR5R0RR6R7R8R R9R:R+RtwritetdebugtrstripR
tsystuniversal_newlinest_translate_newlines(
RR,R%tconnR;treadtnAvailtnMessageR<R>((s7/usr/lib/python2.7/site-packages/salt/utils/nb_popen.pyR$�s.	


%		cC@s�|js
dStjg|jggd�ds3dSytj|jj�|�}Wn9tk
r�}|jdtj	kr�|j
d�S�nX|S(Niiustdin(R1RtselecttosR?R4tOSErrorR R9tEPIPER0(RR)R=R>((s7/usr/lib/python2.7/site-packages/salt/utils/nb_popen.pyR(�s	"
cC@s^|j||�\}}|dkr(dStj|tj�}|jsftj|tj|tjB�nz�tj|gggd�ds�dS|j	|�}|s�|j
|�S|jr�|j|�}nt
|dj|��j|�t
|dj|��j|j��|jr/t
t|�j|�n|SWd|jsYtj|tj|�nXdS(Niuu{0}_buffu_{0}_logger(R-RtfcntltF_GETFLtclosedtF_SETFLRJt
O_NONBLOCKRIRFR0RCRDR+RR?R@RAR
RB(RR,R%REtflagstbuff((s7/usr/lib/python2.7/site-packages/salt/utils/nb_popen.pyR$�s*	 
	%		g{�G�z�?cC@s�d}x�|j�dkr�|jdk	r=d}|j�n|jdk	r_d}|j�n|d7}|dkr�d}|j�\}}|r�tj|�n|r�tj	|�q�nt
j|�q	WdS(Niiid(tpollRtstdoutR&R#R'tcommunicateRR@R7ttimetsleep(Rtintervaltsilent_iterationst
stdoutdatat
stderrdata((s7/usr/lib/python2.7/site-packages/salt/utils/nb_popen.pytpoll_and_read_until_finish�s"


cC@sltt|�j|�|jj�|jjd�|jj�|jjd�|jj�|jj�fS(Ni(RRRVRtflushtseekRRF(RR)((s7/usr/lib/python2.7/site-packages/salt/utils/nb_popen.pyRV�s

N(t__name__t
__module__RR
RRR&R'R*R-R0t	mswindowsR(R$R]RV(((s7/usr/lib/python2.7/site-packages/salt/utils/nb_popen.pyR(s	1					(t__doc__t
__future__RRRRJRBRWR9RIRRRtplatformRbt	win32fileRRt	win32pipeRR2tImportErrorRMRR`RtPopenR(((s7/usr/lib/python2.7/site-packages/salt/utils/nb_popen.pyt<module>s$


Zerion Mini Shell 1.0