[RFC 1/2] patman: introduce RunException
Heiko Thiery
heiko.thiery at gmail.com
Thu Nov 4 19:52:32 CET 2021
The RunException will be throws when the a command's return_code is not
equal zero. With this an external caller can catch that and has access
to the command/args, the result code, the stdout and stderr output.
Signed-off-by: Heiko Thiery <heiko.thiery at gmail.com>
---
tools/patman/tools.py | 16 +++++++++++++---
1 file changed, 13 insertions(+), 3 deletions(-)
diff --git a/tools/patman/tools.py b/tools/patman/tools.py
index 710f1fdcd3..ca1c9114ab 100644
--- a/tools/patman/tools.py
+++ b/tools/patman/tools.py
@@ -313,6 +313,18 @@ def GetTargetCompileTool(name, cross_compile=None):
target_name = name
return target_name, extra_args
+class RunException(Exception):
+ """Exception that is thrown when the command fails"""
+ def __init__(self, args, result):
+ self.args = args
+ self.stdout = result.stdout.strip()
+ self.stderr = result.stderr.strip()
+ self.return_code = result.return_code
+
+ def __str__(self):
+ return ("Error %d running '%s': %s" %
+ (self.return_code,' '.join(self.args), self.stderr))
+
def Run(name, *args, **kwargs):
"""Run a tool with some arguments
@@ -349,9 +361,7 @@ def Run(name, *args, **kwargs):
result = command.RunPipe([all_args], capture=True, capture_stderr=True,
env=env, raise_on_error=False, binary=binary)
if result.return_code:
- raise Exception("Error %d running '%s': %s" %
- (result.return_code,' '.join(all_args),
- result.stderr))
+ raise RunException(all_args, result)
return result.stdout
except:
if env and not PathHasFile(env['PATH'], name):
--
2.30.2
More information about the U-Boot
mailing list