Commit 87c384c5 authored by Dennis Gläser's avatar Dennis Gläser
Browse files

[bin][runcommand] make it possible to suppress traceback

The commands (e.g. pipeline queries via API) may contain sensible
information that we don't want to display e.g. in the output of jobs
from the GitLab CI
parent 35e1f629
......@@ -5,23 +5,27 @@ import subprocess
# execute a command and retrieve the output
def runCommand(command):
def runCommand(command, suppressTraceBack=False, errorMessage=''):
try:
return subprocess.run(command,
shell=True, check=True,
text=True, capture_output=True).stdout
except Exception:
print()
print("An error occurred during subprocess run:")
print("-- command: {}".format(command))
print("-- folder: {}".format(os.getcwd()))
print("-- error: {}".format(sys.exc_info()[1]))
if "git " in command:
print()
print("It seems that a git command failed. Please check:\n"
" -- is the module registered as git repository?\n"
" -- is upstream defined for the branch?\n")
raise
if suppressTraceBack:
sys.excepthook(Exception, Exception(errorMessage), None)
elif not errorMessage:
print("An error occurred during subprocess run:")
print("-- command: {}".format(command))
print("-- folder: {}".format(os.getcwd()))
print("-- error: {}".format(sys.exc_info()[1]))
if "git " in command:
print()
print("It seems that a git command failed. Please check:\n"
" -- is the module registered as git repository?\n"
" -- is upstream defined for the branch?\n")
raise
else:
raise Exception(errorMessage)
# decorator to call function from within the given path
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment