From 6f3e63febdb8677f43bfb9185900c4abfe933ee5 Mon Sep 17 00:00:00 2001 From: Richard Ipsum Date: Wed, 14 May 2014 09:32:34 +0100 Subject: 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. --- morphlib/stagingarea.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'morphlib') 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.' % -- cgit v1.2.1