diff options
author | Lars Wirzenius <lars.wirzenius@codethink.co.uk> | 2011-11-14 16:59:27 +0000 |
---|---|---|
committer | Lars Wirzenius <lars.wirzenius@codethink.co.uk> | 2011-11-14 16:59:27 +0000 |
commit | 0c586238715c2548008366d26490e6fddede43b9 (patch) | |
tree | fdd93a7536ed636d64657d9e7c992abdfee101dc /morphlib/execute.py | |
parent | 09378562ebf6d74a52faa8bd2d5cfcd2587aab5e (diff) | |
download | morph-0c586238715c2548008366d26490e6fddede43b9.tar.gz |
Silence logging during tests
Diffstat (limited to 'morphlib/execute.py')
-rw-r--r-- | morphlib/execute.py | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/morphlib/execute.py b/morphlib/execute.py index 0ffe8133..1315b53e 100644 --- a/morphlib/execute.py +++ b/morphlib/execute.py @@ -39,7 +39,7 @@ class Execute(object): def _setup_env(self): self.env = dict(os.environ) - def run(self, commands, as_root=False, as_fakeroot=False): + def run(self, commands, as_root=False, as_fakeroot=False, _log=True): '''Execute a list of commands. If a command fails (returns non-zero exit code), the rest are @@ -62,14 +62,15 @@ class Execute(object): cwd=self.dirname) out, err = p.communicate() if p.returncode != 0: - logging.error('Exit code: %d' % p.returncode) - logging.error('Standard output and error:\n%s' % - morphlib.util.indent(out)) + if _log: # pragma: no cover + logging.error('Exit code: %d' % p.returncode) + logging.error('Standard output and error:\n%s' % + morphlib.util.indent(out)) raise CommandFailure(command) stdouts.append(out) return stdouts - def runv(self, argv, as_root=False, as_fakeroot=False): + def runv(self, argv, as_root=False, as_fakeroot=False, _log=True): '''Run a command given as a list of argv elements. Return standard output. Raise ``CommandFailure`` if the command @@ -87,9 +88,10 @@ class Execute(object): out, err = p.communicate() if p.returncode != 0: - logging.error('Exit code: %d' % p.returncode) - logging.error('Standard output and error:\n%s' % - morphlib.util.indent(out)) + if _log: # pragma: no cover + logging.error('Exit code: %d' % p.returncode) + logging.error('Standard output and error:\n%s' % + morphlib.util.indent(out)) raise CommandFailure(' '.join(argv)) return out |