diff options
author | Sam Thursfield <sam.thursfield@codethink.co.uk> | 2014-12-18 10:26:04 +0000 |
---|---|---|
committer | Sam Thursfield <sam.thursfield@codethink.co.uk> | 2014-12-18 10:26:04 +0000 |
commit | c57952ef44a0f1f161441970fcf2f27a39b0de7c (patch) | |
tree | b4fee53259020cb4d3da21e352041fac3edf93f5 /morphlib/app.py | |
parent | 70858749d82afe841d06f6a96350168bc3ba51f7 (diff) | |
parent | 9449dbfe1bb1800dfb15de025b87e1846e25e74a (diff) | |
download | morph-c57952ef44a0f1f161441970fcf2f27a39b0de7c.tar.gz |
Merge branch 'sam/improve-command-failure-errors'
Reviewed-By: Richard Ipsum <richard.ipsum@codethink.co.uk>
Reviewed-By: Richard Maw <richard.maw@codethink.co.uk>
Reviewed-By: Daniel Silverstone <daniel.silverstone@codethink.co.uk>
Reviewed-By: Mike Smith <mike.smith@codethink.co.uk>
Diffstat (limited to 'morphlib/app.py')
-rw-r--r-- | morphlib/app.py | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/morphlib/app.py b/morphlib/app.py index 930e023d..eb0ff3b7 100644 --- a/morphlib/app.py +++ b/morphlib/app.py @@ -17,6 +17,7 @@ import cliapp import logging import os +import pipes import sys import time import urlparse @@ -348,7 +349,7 @@ class Morph(cliapp.Application): self.output.write('%s %s\n' % (timestamp, text)) self.output.flush() - def runcmd(self, argv, *args, **kwargs): + def _prepare_for_runcmd(self, argv, args, kwargs): if 'env' not in kwargs: kwargs['env'] = dict(os.environ) @@ -358,16 +359,15 @@ class Morph(cliapp.Application): else: print_command = True - # convert the command line arguments into a string - commands = [argv] + list(args) - for command in commands: - if isinstance(command, list): - for i in xrange(0, len(command)): - command[i] = str(command[i]) - commands = [' '.join(command) for command in commands] - - # print the command line if print_command: + # Print the command line + commands = [argv] + list(args) + for command in commands: + if isinstance(command, list): + for i in xrange(0, len(command)): + command[i] = str(command[i]) + commands = ' '.join(map(pipes.quote, command)) + self.status(msg='# %(cmdline)s', cmdline=' | '.join(commands), chatty=True) @@ -377,9 +377,14 @@ class Morph(cliapp.Application): morphlib.util.log_environment_changes(self, kwargs['env'], prev) self.prev_env = kwargs['env'] - # run the command line + def runcmd(self, argv, *args, **kwargs): + self._prepare_for_runcmd(argv, args, kwargs) return cliapp.Application.runcmd(self, argv, *args, **kwargs) + def runcmd_unchecked(self, argv, *args, **kwargs): + self._prepare_for_runcmd(argv, args, kwargs) + return cliapp.Application.runcmd_unchecked(self, argv, *args, **kwargs) + def parse_args(self, args, configs_only=False): return self.settings.parse_args(args, configs_only=configs_only, |