Yedidyah Bar David has uploaded a new change for review. Change subject: core: Add _executePipe ......................................................................
core: Add _executePipe Change-Id: I4a434fbe1308ac2f603b8ae09756354c11138912 Related-To: https://bugzilla.redhat.com/1059286 Signed-off-by: Yedidyah Bar David <d...@redhat.com> --- M src/otopi/plugin.py 1 file changed, 62 insertions(+), 0 deletions(-) git pull ssh://gerrit.ovirt.org:29418/otopi refs/changes/13/26213/1 diff --git a/src/otopi/plugin.py b/src/otopi/plugin.py index 8a4de0f..390c8a9 100644 --- a/src/otopi/plugin.py +++ b/src/otopi/plugin.py @@ -23,6 +23,7 @@ import os import subprocess +import time import gettext _ = lambda m: gettext.dgettext(message=m, domain='otopi') @@ -327,6 +328,67 @@ def resolveFile(self, file): return self.context.resolveFile(file) + def _executePipe( + self, + popenKwargsList, + ): + """Execute a list of processes in a pipeline. + + popenKwargsList is a list of dictionaries, each a **kwarg for Popen + + Returns: + (rclist, stdout, stderrlist) + + rclist - list of return codes + stderrlist - list of binary blobs, stderrs of the commands + stdout - binary blob output of the last command + + stdin of the first process will be passed as is. The others will + be set to PIPE from their previous. + + stdout of all will be set to PIPE - the last will be returned, the + others will be passed to the following ones. + """ + try: + kwl = [] + popens = [] + rcs = [] + stderrs = [] + num = len(popenKwargsList) + for i, kworig in enumerate(popenKwargsList): + kw = kworig.copy() + kwl.append(kw) + kw['stdout'] = subprocess.PIPE + kw['stderr'] = subprocess.PIPE + self.logger.debug('kwl[%s]: %s' % (i, kwl[i])) + if i>0: + kw['stdin'] = popens[i-1].stdout + if i<num-1: + popens[i-1].stdout.close() + p = subprocess.Popen(**kw) + popens.append(p) + finished = False + while not finished: + # TODO add some (optional) limit? + finished = None not in [ + p.poll() for p in popens + ] + if not finished: + time.sleep(1) # TODO configurable delay? + except: + self.logger.debug( + '_executePipe failed: %s, exception', + popenKwargsList, + exc_info=True + ) + raise + + return ( + [ p.returncode for p in popens ], + popens[-1].stdout, + [ p.stderr for p in popens ], + ) + def executeRaw( self, args, -- To view, visit http://gerrit.ovirt.org/26213 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I4a434fbe1308ac2f603b8ae09756354c11138912 Gerrit-PatchSet: 1 Gerrit-Project: otopi Gerrit-Branch: master Gerrit-Owner: Yedidyah Bar David <d...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches