;ò ‘ç…Dc@sÒdZdklZdkZdkZdkZdkZdkZd„Zde fd„ƒYZ de fd„ƒYZ dfd „ƒYZ d e fd „ƒYZ d d d„Zd„Zedjo eƒndS(sùThis module makes it easier to use other programs to process data. The Process class provides the low-level interface, which you can extend by subclassing. Processes run in the background, so users can still work with your application while they are running. If you don't care about that, you might like to look at Python's builtin popen2 module. The PipeThroughCommand class extends Process to provide an easy way to run other commands. It also, optionally, allows a stream of data to be fed in to the process's standard input, and can collect the output to another stream. Typical usage: rox.processes.PipeThroughCommand(('echo', 'hello'), None, file('output', 'w')).wait() This creates a new process, and execs 'echo hello' in it with output sent to the file 'output' (any file-like object can be used). The wait() runs a recursive mainloop, so that your application can still be used while the command runs, but the wait() itself doesn't return until the command completes. Instead of using a tuple for the command, a string may be passed (eg, "echo hello"). In this case, the shell is used to interpret the command, allowing pipes, wildcards and so on. Be very careful of escaping in this case (think about filenames containing spaces, quotes, apostrophes, etc). (sgNcCsti|tidƒdS(Ni(sfcntlsfdsF_SETFD(sfd((sW/mnt/gmirror/ports/devel/py-roxlib/work/rox-lib2-2.0.5/ROX-Lib2/python/rox/processes.pys _keep_on_exec!ss ChildErrorcBstZdZd„ZRS(s/Raised when the child process reports an error.cCsti||ƒdS(N(s Exceptions__init__sselfsmessage(sselfsmessage((sW/mnt/gmirror/ports/devel/py-roxlib/work/rox-lib2-2.0.5/ROX-Lib2/python/rox/processes.pys__init__%s(s__name__s __module__s__doc__s__init__(((sW/mnt/gmirror/ports/devel/py-roxlib/work/rox-lib2-2.0.5/ROX-Lib2/python/rox/processes.pys ChildError#s s ChildKilledcBstZdZd„ZRS(s8Raised when child died due to a call to the kill method.cCsti|dƒdS(Ns#Operation aborted at user's request(s ChildErrors__init__sself(sself((sW/mnt/gmirror/ports/devel/py-roxlib/work/rox-lib2-2.0.5/ROX-Lib2/python/rox/processes.pys__init__*s(s__name__s __module__s__doc__s__init__(((sW/mnt/gmirror/ports/devel/py-roxlib/work/rox-lib2-2.0.5/ROX-Lib2/python/rox/processes.pys ChildKilled(s sProcesscBswtZdZd„Zd„Zd„Zd„Zd„Zd„Zd„Z e i d„Z d „Z d „Zd „ZRS( sÉThis represents another process. You should subclass this and override the various methods. Use this when you want to run another process in the background, but still be able to communicate with it.cCs t|_dS(N(sNonesselfschild(sself((sW/mnt/gmirror/ports/devel/py-roxlib/work/rox-lib2-2.0.5/ROX-Lib2/python/rox/processes.pys__init__2scCsé|itjpt‚t}}y,|iƒtiƒ\}}ti ƒ}WnD|oti |ƒn|oti |ƒn|i ƒ‚nX|djo³zyoti ddƒti |ƒ|djo!ti |dƒti |ƒn|iƒ|iƒtdƒ‚Wndk}|iƒnXWdtidƒXdpt‚n||_ti |ƒ||_ttdƒ o(ti|itii|iƒ|_n0ti|ititiBti B|iƒ|_|i!ƒdS(s¬Create the subprocess. Calls pre_fork() and forks. The parent then calls parent_post_fork() and returns, while the child calls child_post_fork() and then child_run().iischild_run() returned!Nis io_add_watch("sselfschildsNonesAssertionErrorsstderr_rsstderr_wspre_forksosspipesforkscloses start_errorssetpgidsdup2schild_post_forks child_runs Exceptions tracebacks print_excs_exitserr_from_childshasattrsgobjectsgsinput_add_fullsgdks INPUT_READs _got_errorsstags io_add_watchsIO_INsIO_HUPsIO_ERRsparent_post_fork(sselfs tracebacksstderr_rsstderr_wschild((sW/mnt/gmirror/ports/devel/py-roxlib/work/rox-lib2-2.0.5/ROX-Lib2/python/rox/processes.pysstart5sR              cCsdS(s¹This is called in 'start' just before forking into two processes. If you want to share a resource between both processes (eg, a pipe), create it here. Default method does nothing.N((sself((sW/mnt/gmirror/ports/devel/py-roxlib/work/rox-lib2-2.0.5/ROX-Lib2/python/rox/processes.pyspre_forknscCsdS(s¹This is called in the parent after forking. Free the child part of any resources allocated in pre_fork(). Also called if the fork or pre_fork() fails. Default method does nothing.N((sself((sW/mnt/gmirror/ports/devel/py-roxlib/work/rox-lib2-2.0.5/ROX-Lib2/python/rox/processes.pysparent_post_forktscCsdS(sÄCalled in the child after forking. Release the parent part of any resources allocated in pre_fork(). Also called (in the parent) if the fork or pre_fork() fails. Default method does nothing.N((sself((sW/mnt/gmirror/ports/devel/py-roxlib/work/rox-lib2-2.0.5/ROX-Lib2/python/rox/processes.pyschild_post_forkzscCs|iƒ|iƒdS(sÈAn error occurred before or during the fork (possibly in pre_fork(). Clean up. Default method calls parent_post_fork() and child_post_fork(). On returning, the original exception will be raised.N(sselfsparent_post_forkschild_post_fork(sself((sW/mnt/gmirror/ports/devel/py-roxlib/work/rox-lib2-2.0.5/ROX-Lib2/python/rox/processes.pys start_error€s cCstidƒdS(s#Called in the child process (after child_post_fork()). Do whatever processing is required (perhaps exec another process). If you don't exec, call os._exit(n) when done. DO NOT make gtk calls in the child process, as it shares its parent's connection to the X server until you exec().iN(soss_exit(sself((sW/mnt/gmirror/ports/devel/py-roxlib/work/rox-lib2-2.0.5/ROX-Lib2/python/rox/processes.pys child_runˆscCs/|itj pt‚ti|i |ƒdS(s–Send a signal to all processes in the child's process group. The default, SIGTERM, requests all the processes terminate. SIGKILL is more forceful.N(sselfschildsNonesAssertionErrorsosskillssig(sselfssig((sW/mnt/gmirror/ports/devel/py-roxlib/work/rox-lib2-2.0.5/ROX-Lib2/python/rox/processes.pyskillscCstii|ƒdS(sÎRead some characters from the child's stderr stream. The default method copies to our stderr. Note that 'data' isn't necessarily a complete line; it could be a single character, or several lines, etc.N(ssyssstderrswritesdata(sselfsdata((sW/mnt/gmirror/ports/devel/py-roxlib/work/rox-lib2-2.0.5/ROX-Lib2/python/rox/processes.pysgot_error_output—scCsti|idƒ}|o|i|ƒtSnti|iƒti |i ƒ|` ti |i dƒ\}}t|_ |i|ƒtSdS(Nidi(sossreadsselfserr_from_childsgotsgot_error_outputsTruesclosesgobjects source_removestagswaitpidschildspidsstatussNones child_diedsFalse(sselfssourcescondsstatusspidsgot((sW/mnt/gmirror/ports/devel/py-roxlib/work/rox-lib2-2.0.5/ROX-Lib2/python/rox/processes.pys _got_errorsžs   cCsdS(sÆCalled when the child died (actually, when the child closes its end of the stderr pipe). The child process has already been reaped at this point; 'status' is the status returned by os.waitpid.N((sselfsstatus((sW/mnt/gmirror/ports/devel/py-roxlib/work/rox-lib2-2.0.5/ROX-Lib2/python/rox/processes.pys child_died­s(s__name__s __module__s__doc__s__init__sstartspre_forksparent_post_forkschild_post_forks start_errors child_runssignalsSIGTERMskillsgot_error_outputs _got_errorss child_died(((sW/mnt/gmirror/ports/devel/py-roxlib/work/rox-lib2-2.0.5/ROX-Lib2/python/rox/processes.pysProcess-s   9       sPipeThroughCommandcBswtZdZd„Zd„Zd„Zd„Zd„Zd„Zd„Z d„Z d „Z d „Z e id „ZRS( sKA Process that runs a command with given input and output (Python) streams.cCs¹|tj ot|dƒ o9dk}tƒ}|idƒ|i||ƒ|}nti |ƒ||_ ||_ ||_t|_ t|_d|_d|_t|_t|_dS(s_Execute 'command' with src as stdin and writing to stream dst. If either stream is not a fileno() stream, temporary files will be used as required. Either stream may be None if input or output is not required. Call the wait() method to wait for the command to finish. 'command' may be a string (passed to os.system) or a list (os.execvp). sfilenoNis(ssrcsNoneshasattrsshutils_Tmpsnewsseeks copyfileobjsProcesss__init__sselfscommandsdsts tmp_streamscallbackskilledserrorssFalsesdoneswaiting(sselfscommandssrcsdstsnewsshutil((sW/mnt/gmirror/ports/devel/py-roxlib/work/rox-lib2-2.0.5/ROX-Lib2/python/rox/processes.pys__init__¶s"             cCse|itjpt‚|io@t|idƒo|iiƒ|i|_qatƒ|_ndS(Nsfileno(sselfs tmp_streamsNonesAssertionErrorsdstshasattrsflushs_Tmp(sself((sW/mnt/gmirror/ports/devel/py-roxlib/work/rox-lib2-2.0.5/ROX-Lib2/python/rox/processes.pyspre_forkÔs   cCs t|_dS(N(sNonesselfs tmp_stream(sself((sW/mnt/gmirror/ports/devel/py-roxlib/work/rox-lib2-2.0.5/ROX-Lib2/python/rox/processes.pys start_erroràscCs¦|ip tddƒ}ti|iƒdƒtdƒytidddƒWnnX|io'ti|i iƒdƒtdƒn|i ƒti dƒdS(s:Assigns file descriptors and calls child_run_with_streams.s /dev/nullsriiN( sselfssrcsfilesossdup2sfilenos _keep_on_execslseeksdsts tmp_streamschild_run_with_streamss_exit(sselfssrc((sW/mnt/gmirror/ports/devel/py-roxlib/work/rox-lib2-2.0.5/ROX-Lib2/python/rox/processes.pys child_runãs   cCs_t|itƒo.ti|iƒdjotidƒq[nti|id|iƒdS(sThis is run by the child process. stdin and stdout have already been set up. Should call exec() or os._exit() to finish. Default method execs self.command.iN(s isinstancesselfscommandsstrsosssystems_exitsexecvp(sself((sW/mnt/gmirror/ports/devel/py-roxlib/work/rox-lib2-2.0.5/ROX-Lib2/python/rox/processes.pyschild_run_with_streamsõs cCs.|io|i|ijo t|_ndS(N(sselfsdsts tmp_streamsNone(sself((sW/mnt/gmirror/ports/devel/py-roxlib/work/rox-lib2-2.0.5/ROX-Lib2/python/rox/processes.pysparent_post_forkÿscCs|i|7_dS(N(sselfserrorssdata(sselfsdata((sW/mnt/gmirror/ports/devel/py-roxlib/work/rox-lib2-2.0.5/ROX-Lib2/python/rox/processes.pysgot_error_outputscCsM|o#tdt|iƒ|fƒ‚ntdt|iƒ|fƒ‚dS(sªRaise an exception here if errors (the string the child process wrote to stderr) or status (the status from waitpid) seems to warrent it. It will be returned by wait().sErrors from command '%s': %ss)Command '%s' returned an error code (%d)!N(serrorss ChildErrorsstrsselfscommandsstatus(sselfserrorssstatus((sW/mnt/gmirror/ports/devel/py-roxlib/work/rox-lib2-2.0.5/ROX-Lib2/python/rox/processes.pys check_errorss#cCs6|iiƒ}|iotƒ|_nZ|p|oBy|i||ƒt|_Wq‚t j o}||_q‚Xn t|_|itjpt |it ƒpt ‚|itjo;|i o-|i idƒ|ii|i iƒƒq÷nt|_ |io(|ipt ‚t|_tiƒndS(Ni(sselfserrorssstripskilleds ChildKilledsdonesstatuss check_errorssTrues Exceptionses isinstancesAssertionErrors tmp_streamsseeksdstswritesreadsNoneswaitingsFalsesgs main_quit(sselfsstatusserrorsse((sW/mnt/gmirror/ports/devel/py-roxlib/work/rox-lib2-2.0.5/ROX-Lib2/python/rox/processes.pys child_died s(   * !   cCse|itjo|iƒnt|_x|i otiƒq*W|itj o |i‚ndS(sVRun a recursive mainloop until the command terminates. Raises an exception on error.N( sselfschildsNonesstartsTrueswaitingsdonesgsmain(sself((sW/mnt/gmirror/ports/devel/py-roxlib/work/rox-lib2-2.0.5/ROX-Lib2/python/rox/processes.pyswait+s  cCsd|_ti||ƒdS(Ni(sselfskilledsProcessskillssig(sselfssig((sW/mnt/gmirror/ports/devel/py-roxlib/work/rox-lib2-2.0.5/ROX-Lib2/python/rox/processes.pyskill6s (s__name__s __module__s__doc__s__init__spre_forks start_errors child_runschild_run_with_streamssparent_post_forksgot_error_outputs check_errorss child_diedswaitssignalsSIGTERMskill(((sW/mnt/gmirror/ports/devel/py-roxlib/work/rox-lib2-2.0.5/ROX-Lib2/python/rox/processes.pysPipeThroughCommand³s         sw+bs-tmpcCs¨dk}y|i|d|ƒSWnnXdk}|i|iddƒ |ƒ}ti |ti ti Bti Bdƒ}|iti||ƒ|ƒ}||_|SdS(sNCreate a seekable, randomly named temp file (deleted automatically after use).Nssuffixii@BiÀ(stempfilesNamedTemporaryFilesmodessuffixsrandomsmktempsrandintsnamesossopensO_RDWRsO_CREATsO_EXCLsfdsTemporaryFileWrappersfdopenstmp(smodessuffixstmpsnamestempfilesrandomsfd((sW/mnt/gmirror/ports/devel/py-roxlib/work/rox-lib2-2.0.5/ROX-Lib2/python/rox/processes.pys_Tmp:s   & c s·d„}d„}dGHtƒ}|idƒ|dI|iƒti|iƒdƒ|idƒ|i ƒdjpt ‚d GHd GHy"|d t t ƒdpt ‚Wnt j o|ƒnXdpt ‚d GH|d t t ƒdGHdk l}|ƒ}|dt |ƒ|iƒdjpt ‚dGH|ƒ}|ddft |ƒ|iƒdjpt ‚dGH|idƒ|d||ƒ|iƒdjpt ‚dGH|idƒ|idƒ|dt |ƒ|idƒ|i ƒdjpt ‚dGHtƒ}|idƒ|idƒ|idƒ|idƒ|d||ƒ|idƒ|i ƒdjpt ‚dGHy|dt t ƒWnt j o|ƒnXdpt ‚dGHy|d t t ƒWnt j o|ƒnXdpt ‚d!GH|i}tii|ƒpt ‚t }tii|ƒ pt ‚d"GHtd#t t ƒ‰‡d$†}tid%|ƒyˆiƒdpt ‚Wntj onXd&GHd'S((sCheck that this module works.cCstiƒd}d|GHdS(Nis(error reported was '%s')(ssyssexc_infoserror(serror((sW/mnt/gmirror/ports/devel/py-roxlib/work/rox-lib2-2.0.5/ROX-Lib2/python/rox/processes.pysshowOscCst|||ƒiƒdS(N(sPipeThroughCommandscommandssrcsdstswait(scommandssrcsdst((sW/mnt/gmirror/ports/devel/py-roxlib/work/rox-lib2-2.0.5/ROX-Lib2/python/rox/processes.pyspipe_through_commandSssTest _Tmp()...sHellos sWorldis Hello WorldsTest pipe_through_command():sTry an invalid command...sbad_command_1234sTry a valid command...sexit 0s!Writing to a non-fileno stream...(sStringIOs echo HellosHello sTry with args...sechos&Reading from a stream to a StringIO...iscatsHello Hello WorldsWriting to a fileno stream...secho FoosFoo s Read and write fileno streams...s123sDetect non-zero exit value...sexit 1sDetect writes to stderr...s#echo one >&2; sleep 2; echo two >&2sCheck tmp file is deleted...s%Check we can kill a runaway proces...ssleep 100; exit 1csˆiƒdS(N(sptcskill((sptc(sW/mnt/gmirror/ports/devel/py-roxlib/work/rox-lib2-2.0.5/ROX-Lib2/python/rox/processes.pysstop§siÐsAll tests passed!N(sshowspipe_through_commands_Tmps test_fileswritesflushsossfilenosseeksreadsAssertionErrorsNones ChildErrors cStringIOsStringIOsasgetvaluestruncatessrcsnamespathsexistssPipeThroughCommandsptcsstopsgs timeout_addswaits ChildKilled( sassrcs test_filesnamesshowsStringIOsptcsstopspipe_through_command((sptcsW/mnt/gmirror/ports/devel/py-roxlib/work/rox-lib2-2.0.5/ROX-Lib2/python/rox/processes.pys_testLs˜                          s__main__(s__doc__sroxsgsgobjectsosssyssfcntlssignals _keep_on_execs Exceptions ChildErrors ChildKilledsProcesssPipeThroughCommands_Tmps_tests__name__( sfcntlsgsProcesss _keep_on_execssignals ChildKilledsPipeThroughCommandssyss_Tmpsgobjects ChildErrorsoss_test((sW/mnt/gmirror/ports/devel/py-roxlib/work/rox-lib2-2.0.5/ROX-Lib2/python/rox/processes.pys?s    †‡ f