Commit 99886261 authored by Łukasz Nowak's avatar Łukasz Nowak

Add utility methods.

pipeCommand allows to simulate shell pipes.

failIfPathExists allows to stop in case of path which exists.
parent 70a58162
......@@ -172,6 +172,32 @@ class Script:
self.cleanup_dir_list.append(extract_dir)
return extract_dir
def pipeCommand(self, command_list_list, *args, **kwargs):
"""Allows to do shell like pipes (|)"""
subprocess_list = []
previous = None
kwargs['stdout'] = subprocess.PIPE
run_list = []
for command_list in command_list_list:
if previous is not None:
kwargs['stdin'] = previous.stdout
p = subprocess.Popen(command_list, *args, **kwargs)
if previous is not None:
previous.stdout.close()
subprocess_list.append((p, command_list))
run_list.append(' '.join(command_list))
previous = p
self.logger.info('Running: %r' % ' | '.join(run_list))
subprocess_list.reverse()
[q[0].wait() for q in subprocess_list]
for q in subprocess_list:
if q[0].returncode != 0:
raise zc.buildout.UserError('Failed while running command %r' % q[1])
def failIfPathExists(self, path):
if os.path.lexists(path):
raise zc.buildout.UserError('Path %r exists, cannot continue' % path)
def copyTree(self, origin, destination, ignore_dir_list=None):
"""Recursively Copy directory.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment