summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Thursfield <sam.thursfield@codethink.co.uk>2015-01-02 12:43:10 +0000
committerSam Thursfield <sam.thursfield@codethink.co.uk>2015-01-02 12:43:10 +0000
commit30aaa46e250a1bd8081283839abd7d5aab97fb1e (patch)
treec114ba7b45457f2dd19cf6de19163faa4fb0b012
parentf33748d6e6795751e7ea628d5f4e8478353a88ee (diff)
parent6f5c4a44a124e018982cffe06fd10e93ea65f446 (diff)
downloadmorph-30aaa46e250a1bd8081283839abd7d5aab97fb1e.tar.gz
Merge branch 'sam/fix-command-logging'
Reviewed-By: Paul Sherwood <paul.sherwood@codethink.co.uk> Reviewed-By: Mike Smith <mike.smith@codethink.co.uk>
-rw-r--r--morphlib/app.py41
1 files changed, 25 insertions, 16 deletions
diff --git a/morphlib/app.py b/morphlib/app.py
index eb0ff3b7..177bce45 100644
--- a/morphlib/app.py
+++ b/morphlib/app.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2011-2014 Codethink Limited
+# Copyright (C) 2011-2015 Codethink Limited
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -309,6 +309,11 @@ class Morph(cliapp.Application):
if (submod.url, submod.commit) not in done:
subs_to_process.add((submod.url, submod.commit))
+ def _write_status(self, text):
+ timestamp = time.strftime('%Y-%m-%d %H:%M:%S', time.gmtime())
+ self.output.write('%s %s\n' % (timestamp, text))
+ self.output.flush()
+
def status(self, **kwargs):
'''Show user a status update.
@@ -345,9 +350,20 @@ class Morph(cliapp.Application):
ok = verbose or error or (not quiet and not chatty)
if ok:
- timestamp = time.strftime('%Y-%m-%d %H:%M:%S', time.gmtime())
- self.output.write('%s %s\n' % (timestamp, text))
- self.output.flush()
+ self._write_status(text)
+
+ def _commandline_as_message(self, argv, args):
+ '''Create a status string for a command that's about to be executed.'''
+
+ commands = []
+ for command in [argv] + list(args):
+ if isinstance(command, list):
+ command_str = ' '.join(map(pipes.quote, command))
+ else:
+ command_str = pipes.quote(command)
+ commands.append(command_str)
+
+ return '# ' + ' | '.join(commands)
def _prepare_for_runcmd(self, argv, args, kwargs):
if 'env' not in kwargs:
@@ -359,18 +375,11 @@ class Morph(cliapp.Application):
else:
print_command = True
- 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)
+ if print_command and self.settings['verbose']:
+ # Don't call self.status() here, to avoid writing the message to
+ # the log as well as to the console. The cliapp.runcmd() function
+ # will also log the command, and it's messy having it logged twice.
+ self._write_status(self._commandline_as_message(argv, args))
# Log the environment.
prev = getattr(self, 'prev_env', {})