+
+
+def logcmd(cmd):
+ if isinstance(cmd, basestring):
+ print(cmd, file=sys.stderr)
+ else:
+ print(' '.join(map(quote, cmd)), file=sys.stderr)
+
+def exc(cmd, shell=False):
+ logcmd(cmd)
+ check_call(cmd, shell=shell)
+
+def exo(cmd, stdin=None, stdout=True, stderr=False, shell=False, check=True):
+ logcmd(cmd)
+ p = Popen(cmd,
+ stdin=None,
+ stdout=(PIPE if stdout else None),
+ stderr=PIPE,
+ shell=shell)
+ out, err = p.communicate()
+ if check and p.returncode != 0:
+ raise Exception('subprocess %r failed with status %d, stderr: %r'
+ % (' '.join(map(quote, cmd)), p.returncode, err))
+ return out, err, p