aboutsummaryrefslogtreecommitdiff
path: root/gn3
diff options
context:
space:
mode:
authorBonfaceKilz2021-06-29 13:06:25 +0300
committerBonfaceKilz2021-06-29 14:50:30 +0300
commit14522d155d37f9df14587c23d116248177876df5 (patch)
tree3a912cb9b992cb56d7cbf269f9a858fa73699425 /gn3
parent045ff342097ba31bf443e1db5f548226ede1220f (diff)
downloadgenenetwork3-14522d155d37f9df14587c23d116248177876df5.tar.gz
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.
Diffstat (limited to 'gn3')
-rw-r--r--gn3/commands.py7
1 files changed, 4 insertions, 3 deletions
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}