summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarkus Lehtonen <markus.lehtonen@linux.intel.com>2017-03-24 16:43:24 +0200
committerRichard Purdie <richard.purdie@linuxfoundation.org>2017-03-27 08:15:07 +0100
commit68190b511531886f498a3cf57f9ad7fb126d5fcb (patch)
tree74ee2b21c9ad20f1d2afa7d378ad08b2794ec970
parent5e3eaf7c57ee6565080bfeab995c81c2774381fa (diff)
downloadpoky-68190b511531886f498a3cf57f9ad7fb126d5fcb.tar.gz
oeqa.utils.commands: limit runCmd exception output
Make it possible to limit the length of output lines shown in runCmd exceptions. E.g when running bitbake we easily get thousands of lines of log output, where only the last few (tens) are interesting or relevant when an error occurs. (From OE-Core rev: 403dd205828002d6ef4e8b474aedb6082289e22f) Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r--meta/lib/oeqa/utils/commands.py13
1 files changed, 10 insertions, 3 deletions
diff --git a/meta/lib/oeqa/utils/commands.py b/meta/lib/oeqa/utils/commands.py
index 6528a98427..cd7a5e3b12 100644
--- a/meta/lib/oeqa/utils/commands.py
+++ b/meta/lib/oeqa/utils/commands.py
@@ -97,7 +97,8 @@ class Result(object):
97 pass 97 pass
98 98
99 99
100def runCmd(command, ignore_status=False, timeout=None, assert_error=True, native_sysroot=None, **options): 100def runCmd(command, ignore_status=False, timeout=None, assert_error=True,
101 native_sysroot=None, limit_exc_output=0, **options):
101 result = Result() 102 result = Result()
102 103
103 if native_sysroot: 104 if native_sysroot:
@@ -117,10 +118,16 @@ def runCmd(command, ignore_status=False, timeout=None, assert_error=True, native
117 result.pid = cmd.process.pid 118 result.pid = cmd.process.pid
118 119
119 if result.status and not ignore_status: 120 if result.status and not ignore_status:
121 exc_output = result.output
122 if limit_exc_output > 0:
123 split = result.output.splitlines()
124 if len(split) > limit_exc_output:
125 exc_output = "\n... (last %d lines of output)\n" % limit_exc_output + \
126 '\n'.join(split[-limit_exc_output:])
120 if assert_error: 127 if assert_error:
121 raise AssertionError("Command '%s' returned non-zero exit status %d:\n%s" % (command, result.status, result.output)) 128 raise AssertionError("Command '%s' returned non-zero exit status %d:\n%s" % (command, result.status, exc_output))
122 else: 129 else:
123 raise CommandError(result.status, command, result.output) 130 raise CommandError(result.status, command, exc_output)
124 131
125 return result 132 return result
126 133