From 14522d155d37f9df14587c23d116248177876df5 Mon Sep 17 00:00:00 2001 From: BonfaceKilz Date: Tue, 29 Jun 2021 13:06:25 +0300 Subject: gn3: commands: Add extra arg that sets the success codes to check * gn3/commands.py (run_cmd): Some commands like "diff" return non-standard error codes. To make this fn more robust, add an extra optional argument that sets what successful codes to check. --- gn3/commands.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'gn3') diff --git a/gn3/commands.py b/gn3/commands.py index 459ccee..0f526d8 100644 --- a/gn3/commands.py +++ b/gn3/commands.py @@ -74,10 +74,11 @@ Returns the name of the specific redis hash for the specific task. return unique_id -def run_cmd(cmd: str) -> Dict: +def run_cmd(cmd: str, success_codes: List = [0]) -> Dict: """Run CMD and return the CMD's status code and output as a dict""" - results = subprocess.run(cmd, capture_output=True, shell=True, check=False) + results = subprocess.run(cmd, capture_output=True, shell=True, + check=False) out = str(results.stdout, 'utf-8') - if results.returncode < 0: # Error! + if results.returncode not in success_codes: # Error! out = str(results.stderr, 'utf-8') return {"code": results.returncode, "output": out} -- cgit v1.2.3