mò fDc@sGdkZeidjZdkZdkZdkZeoCdkZdkZdkTdfd„ƒYZ dfd„ƒYZ n%dk Z dk Z dk Z dkZddd d gZyeid ƒZWn d ZnXyeWnej od ZdZnXgZd„ZdZdZd„Zd„Zdefd„ƒYZdS(Ntwin32(t*t STARTUPINFOcBs tZdZdZdZdZRS(Ni(t__name__t __module__tdwFlagstNonet hStdInputt hStdOutputt hStdError(((t'/home/samy/kbilliards/wafadmin/pproc.pyR4st pywintypescBstZeZRS(N(RRtIOErrorterror(((R R 9stPopentPIPEtSTDOUTtcallt SC_OPEN_MAXiiicCs xtD]}|iƒqWdS(N(t_activetinsttpoll(R((R t_cleanupQsiÿÿÿÿiþÿÿÿcOst||ŽiƒS(sÓRun command with arguments. Wait for command to complete, then return the returncode attribute. The arguments are the same as for the Popen constructor. Example: retcode = call(["ls", "-l"]) N(Rtargstkwargstwait(RR((R RYscCsOg}t}x3|D]+}g}|o|idƒnd|jp d|j}|o|idƒnx–|D]Ž}|djo|i|ƒqo|djo2|idt|ƒdƒg}|idƒqo|o|i |ƒg}n|i|ƒqoW|o|i |ƒn|o|i |ƒ|idƒqqWdi |ƒS( s• Translate a sequence of arguments into a command line string, using the same rules as the MS C runtime: 1) Arguments are delimited by white space, which is either a space or a tab. 2) A string surrounded by double quotation marks is interpreted as a single argument, regardless of white space contained within. A quoted string can be embedded in an argument. 3) A double quotation mark preceded by a backslash is interpreted as a literal double quotation mark. 4) Backslashes are interpreted literally, unless they immediately precede a double quotation mark. 5) If backslashes immediately precede a double quotation mark, every pair of backslashes is interpreted as a literal backslash. If the number of backslashes is odd, the last backslash escapes the next double quotation mark as described in rule 3. t s t"s\is\"tN( tresulttFalset needquotetseqtargtbs_buftappendtctlentextendtjoin(R R$RRR!R"((R t list2cmdlineds:     cBsâtZddddddeeddeddd„ Zd„ZeoOd„Zd„Zd„Z d„Z d„Z d „Z d „Z dd „ZnLd „Zd „Zd„Zd„Z d„Zd„Z d„Z dd„ZRS(NicCsýtƒt|ttfƒptdƒ‚nto8|d j ot dƒ‚n|ot dƒ‚q¦n;| d j ot dƒ‚n|djot dƒ‚nd |_d |_d |_d |_d |_| |_|i|||ƒ\}}}}}}|i||||| | | | || ||||||ƒ|ot!i"|d|ƒ|_n|o?| ot!i"|d|ƒ|_q¦t!i"|d |ƒ|_n|o?| ot!i"|d|ƒ|_qìt!i"|d |ƒ|_nt#i$|ƒd S( sCreate new Popen instance.sbufsize must be an integers0preexec_fn is not supported on Windows platformss/close_fds is not supported on Windows platformss2startupinfo is only supported on Windows platformsis4creationflags is only supported on Windows platformstwbtrUtrbN(%Rt isinstancetbufsizetinttlongt TypeErrort mswindowst preexec_fnRt ValueErrort close_fdst startupinfot creationflagstselftstdintstdouttstderrtpidt returncodetuniversal_newlinest _get_handlestp2creadtp2cwritetc2preadtc2pwriteterrreadterrwritet_execute_childRt executabletcwdtenvtshelltostfdopenRR#(R7RR-RFR8R9R:R2R4RIRGRHR=R5R6RCRARDRBR?R@((R t__init__©sJ         '   cCs(|iddƒ}|iddƒ}|S(Ns s s (tdatatreplace(R7RM((R t_translate_newlinesõsc CsŠ|djo"|djo|djodSnd\}}d\} }d\}}|djot t ƒ}nƒ|t jo7t ddƒ\}}|iƒ}ti|dƒ}n?t|ƒtijoti|ƒ}nti|iƒƒ}|i|ƒ}|djot tƒ}nƒ|t jo7t ddƒ\} }| iƒ} ti| dƒ} n?t|ƒtijoti|ƒ}nti|iƒƒ}|i|ƒ}|djot tƒ}nš|t jo7t ddƒ\}}|iƒ}ti|dƒ}nV|tjo |}n?t|ƒtijoti|ƒ}nti|iƒƒ}|i|ƒ}||| |||fS(s|Construct and return tupel with IO objects: p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite iN(NNNNNN(NN(NN(NN(R8RR9R:R?R@RARBRCRDt GetStdHandletSTD_INPUT_HANDLERt CreatePipetDetachtmsvcrttopen_osfhandlettypettypestIntTypet get_osfhandletfilenoR7t_make_inheritabletSTD_OUTPUT_HANDLEtSTD_ERROR_HANDLER( R7R8R9R:RCR?R@RDRBRA((R R>ÿsN'              cCsttƒ|tƒddtƒS(s2Return a duplicate of handle, which is inheritableiiN(tDuplicateHandletGetCurrentProcessthandletDUPLICATE_SAME_ACCESS(R7R`((R R[;s  cCs‰tiitiitdƒƒdƒ}tii|ƒpKtiitiitiƒdƒ}tii|ƒpt dƒ‚q…n|S(s,Find and return absolut path to w9xpopen.exeis w9xpopen.exesZCannot locate w9xpopen.exe, which is needed for Popen to work with your shell or platform.N( RJtpathR'tdirnametGetModuleFileNametw9xpopentexiststsyst exec_prefixt RuntimeError(R7Re((R t_find_w9xpopenBs  c Csõt|tiƒpt|ƒ}ntƒ}|djo |}nd| ||fjo.|i t O_ | |_||_||_n| o˜|i tO_ t|_tiiddƒ}|d|}tƒdjptii|ƒiƒdjo*|iƒ}d||f}| t!O} q&ny4t"||ddd| |||ƒ \}}}}Wn't*i+j o}t-|iŒ‚nX||_.||_(|i/ƒ| djo| i/ƒn|djo|i/ƒn|djo|i/ƒndS( s$Execute program (MS Windows version)tCOMSPECscmd.exes /c ls command.coms"%s" %siN(0R,RRWt StringTypesR(Rtdefault_startupinfoR5RR?RBRDRtSTARTF_USESTDHANDLESRRR RItSTARTF_USESHOWWINDOWtSW_HIDEt wShowWindowRJtenvirontgettcomspect GetVersionRbtbasenametlowerR7RjReR6tCREATE_NEW_CONSOLEt CreateProcessRFRHRGthpthtR;ttidR R tet WindowsErrort_handletClose(R7RRFR2R4RGRHR=R5R6RIR?R@RARBRCRDR;RtR|RmRzR{R}Re((R RERsN       /        cCsW|idjo@t|idƒtjo#t|iƒ|_ti|ƒqPn|iS(sQCheck if child process has terminated. Returns returncode attribute.iN( R7R<RtWaitForSingleObjectRt WAIT_OBJECT_0tGetExitCodeProcessRtremove(R7((R R¢s cCsL|idjo5t|itƒ}t|iƒ|_ti |ƒn|iS(sOWait for child process to terminate. Returns returncode attribute.N( R7R<RRRtINFINITEtobjRƒRR„(R7R†((R R¬s cCs|i|iƒƒdS(N(tbufferR#tfhtread(R7RˆR‡((R t _readerthread¶scCs²d}d}|ioEg}tid|id|i|fƒ}|it ƒ|i ƒn|ioEg}tid|id|i|fƒ}|it ƒ|i ƒn|i o2|djo|i i|ƒn|i iƒn|io|iƒn|io|iƒn|djo|d}n|djo|d}n|ioHttdƒo8|o|i|ƒ}n|o|i|ƒ}qžn|iƒ||fS(szInteract with process: Send data to stdin. Read data from stdout and stderr, until end-of-file is reached. Wait for process to terminate. The optional input argument should be a string to be sent to the child process, or None, if no data should be sent to the child. communicate() returns a tuple (stdout, stderr).ttargetRitnewlinesN(RR9R:R7t threadingtThreadRŠt stdout_threadt setDaemontTruetstartt stderr_threadR8tinputtwritetcloseR'R=thasattrtopenROR(R7R”R9R:RR“((R t communicateºsD           c Csqd\}}d\} }d\}}|djonP|tjot i ƒ\}}n-t |ƒt i jo |}n |iƒ}|djonP|tjot i ƒ\} }n-t |ƒt i jo |}n |iƒ}|djong|tjot i ƒ\}}nD|tjo |}n-t |ƒt i jo |}n |iƒ}||| |||fS(s|Construct and return tupel with IO objects: p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite N(NN(NN(NN(RR?R@RARBRCRDR8RRJtpipeRVRWRXRZR9R:R( R7R8R9R:RCR?R@RDRBRA((R R>ós8                 cCs\y ti}Wntj o d}nXti|tiƒ}ti|ti||BƒdS(Ni(tfcntlt FD_CLOEXECt cloexec_flagtAttributeErrortfdtF_GETFDtoldtF_SETFD(R7RŸR¡R((R t_set_cloexec_flag s   cCsMxFtdtƒD]5}||joqnyti|ƒWqqXqWdS(Ni(trangetMAXFDtitbutRJR–(R7R§R¦((R t _close_fds*s cCsat|tiƒo |g}n| oddg|}n|d jo|d}ntiƒ\}}|i |ƒti ƒ|_|idjoy—| oti| ƒn| oti| ƒn|oti|ƒnti|ƒ| oti| dƒn|oti|dƒn|oti|dƒn| oti| ƒn|o!|| fjoti|ƒn|o$|| |fjoti|ƒn|o|id|ƒn|d joti|ƒn|ot|ƒn|d joti||ƒnti|||ƒWn\t i!ƒ\}}}t%i&|||ƒ}di(|ƒ|_)ti*|t+i,|ƒƒnXti-dƒnti|ƒ| o| oti| ƒn|o| oti|ƒn|o|oti|ƒnti.|d ƒ}ti|ƒ|djo,ti0|idƒt+i1|ƒ}|‚nd S( sExecute program (POSIX version)s/bin/shs-ciiiR§RiÿiN(3R,RRWRlRIRFRRJRšt errpipe_readt errpipe_writeR7R£tforkR;R@R–RARCR?tdup2RBRDR4R¨RGtchdirR2tapplyRHtexecvptexecvpeRgtexc_infotexc_typet exc_valuettbt tracebacktformat_exceptiont exc_linesR'tchild_tracebackR•tpickletdumpst_exitR‰RMtwaitpidtloadstchild_exception(R7RRFR2R4RGRHR=R5R6RIR?R@RARBRCRDR·R¾RªR²R´RMR©R³((R RE4sz           cCsjti|ƒoti|ƒ |_n3ti|ƒoti|ƒ|_n tdƒ‚t i |ƒdS(NsUnknown child exit status!( RJt WIFSIGNALEDtststWTERMSIGR7R<t WIFEXITEDt WEXITSTATUSRiRR„(R7RÀ((R t_handle_exitstatus—s  cCsw|idjo`yCti|itiƒ\}}||ijo|i|ƒnWqpti j oqpXn|iS(sQCheck if child process has terminated. Returns returncode attribute.N( R7R<RRJR¼R;tWNOHANGRÀRÄR (R7R;RÀ((R R£s cCsC|idjo,ti|idƒ\}}|i|ƒn|iS(sOWait for child process to terminate. Returns returncode attribute.iN(R7R<RRJR¼R;RÀRÄ(R7R;RÀ((R R°s c Cs¶g}g}d}d} |io9|iiƒ|o|i |iƒq[|ii ƒn|io|i |iƒg}n|io|i |iƒg} nxj|p|o[t i ||gƒ\}} }|i| joUti|iiƒ|d ƒ}||}|p!|ii ƒ|i|iƒq7n|i|joZti|iiƒdƒ}|djo!|ii ƒ|i|iƒn|i |ƒn|i|joZti|iiƒdƒ}|djo!|ii ƒ|i|iƒn| i |ƒq¦q¦W|djodi|ƒ}n| djodi| ƒ} n|ioHttdƒo8|o|i|ƒ}n| o|i| ƒ} q¢n|iƒ|| fS(szInteract with process: Send data to stdin. Read data from stdout and stderr, until end-of-file is reached. Wait for process to terminate. The optional input argument should be a string to be sent to the child process, or None, if no data should be sent to the child. communicate() returns a tuple (stdout, stderr).iiRRŒN(tread_sett write_setRR9R:R7R8tflushR”R#R–tselecttrlisttwlisttxlistRJR•RZt bytes_writtenR„R‰RMR'R=R—R˜ROR( R7R”RÊRÌR9RÇRMRÍRÆR:RË((R R™¹s`               (RRRRRLROR1R>R[RjRERRRŠR™R£R¨RÄ(((R R¨s&0L  <   P 9 - c (RgtplatformR1RJRWRµRRTt _subprocessRR RÉterrnoR›R¹t__all__tsysconfR¥Rt NameErrorR‘RRRRRR(tobjectR(RR1RÉRRÑRÐRTRRR‘R›RRRgR RWRRJRRµR(RR¥R¹((R t?s@               D