diff options
author | Richard Ipsum <richard.ipsum@codethink.co.uk> | 2014-05-14 09:32:34 +0100 |
---|---|---|
committer | Richard Ipsum <richard.ipsum@codethink.co.uk> | 2014-05-14 16:20:35 +0100 |
commit | 6f3e63febdb8677f43bfb9185900c4abfe933ee5 (patch) | |
tree | 9ece6e98fa2b06ff5a6e2ad94fb6b9bdd08049e2 /morphlib/stagingarea.py | |
parent | d2897cf5f6b66144dccca2e357f1a64c44152b6d (diff) | |
download | morph-6f3e63febdb8677f43bfb9185900c4abfe933ee5.tar.gz |
Add logfile kwarg to staging area runcmd
We use tee to write the output to a file as well as to stdout.
Using Popen it should be straight forward to send the output to a pipe and
then read that pipe and write to wherever.
At the moment morph uses cliapp's runcmd rather than Popen. cliapp's runcmd
is a blocking call, so we're not able to read from the pipe until the
command has completed, which prevents real time logging to a number of files.
One solution to this problem might be to spawn a thread which opens a pipe
to the command being executed, the thread then reads from the pipe and writes
to our collection of logfiles.
Diffstat (limited to 'morphlib/stagingarea.py')
-rw-r--r-- | morphlib/stagingarea.py | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/morphlib/stagingarea.py b/morphlib/stagingarea.py index 61f9e660..124edabf 100644 --- a/morphlib/stagingarea.py +++ b/morphlib/stagingarea.py @@ -309,7 +309,14 @@ class StagingArea(object): real_argv += argv try: - return self._app.runcmd(real_argv, **kwargs) + if 'logfile' in kwargs and kwargs['logfile'] != None: + logfile = kwargs['logfile'] + del kwargs['logfile'] + + teecmd = ['tee', '-a', logfile] + return self._app.runcmd(real_argv, teecmd, **kwargs) + else: + return self._app.runcmd(real_argv, **kwargs) except cliapp.AppException as e: raise cliapp.AppException('In staging area %s: running ' 'command \'%s\' failed.' % |