4 class CalledProcessError(subprocess.CalledProcessError):
8 """An advanced shell, with the ability to do dry-run and log commands"""
9 def __init__(self, logger = False, dry = False):
10 """ `logger` The logger
11 `dry` Whether or not to not run any commands, and just print"""
14 def call(self, *args):
15 if self.dry or self.logger:
16 self.logger.info("$ " + ' '.join(args))
20 if hasattr(self.logger, "verbose"):
21 # this is a special short-circuit to make redrawing
22 # output from Git work
23 proc = subprocess.Popen(args, stdout=sys.stdout, stderr=sys.stderr)
25 proc = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
27 proc = subprocess.Popen(args)
28 stdout, _ = proc.communicate()
29 if self.logger and stdout: self.logger.info(stdout)
31 raise CalledProcessError(proc.returncode, args)