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/util.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/util.py')
-rw-r--r-- | morphlib/util.py | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/morphlib/util.py b/morphlib/util.py index 6f735387..e7a8a50e 100644 --- a/morphlib/util.py +++ b/morphlib/util.py @@ -16,6 +16,7 @@ import contextlib import itertools import os +import pipes import re import subprocess import textwrap @@ -41,7 +42,6 @@ try: from multiprocessing import cpu_count except NotImplementedError: # pragma: no cover cpu_count = lambda: 1 -import os def indent(string, spaces=4): @@ -626,3 +626,18 @@ def containerised_cmdline(args, cwd='.', root='/', binds=(), cmdargs.append(root) cmdargs.extend(args) return unshared_cmdline(cmdargs, root=root, **kwargs) + + +def error_message_for_containerised_commandline( + argv, err, container_kwargs): # pragma: no cover + '''Return a semi-readable error message for a containerised command.''' + + # This function should do some formatting of the container_kwargs dict, + # rather than just dumping it in the error message, but that is better than + # nothing. + + argv_string = ' '.join(map(pipes.quote, argv)) + return 'Command failed: %s:\n' \ + 'Containerisation settings: %s\n' \ + 'Error output:\n%s' \ + % (argv_string, container_kwargs, err) |