Skip to content
Snippets Groups Projects
Commit dd0b83b4 authored by Dennis Gläser's avatar Dennis Gläser
Browse files

[bin][util] add python file with reusable functionality

parent 06e80c55
No related branches found
No related tags found
1 merge request!2230Feature/install script generator
import os
import sys
import functools
import subprocess
# execute a command and retrieve the output
def runCommand(command):
try:
return subprocess.run(command, shell=True, check=True,
text=True, capture_output=True).stdout
except Exception as e:
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
# decorator to call function from within the given path
def callFromPath(path):
def decorator_callFromPath(callFunc):
@functools.wraps(callFunc)
def wrapper_callFromPath(*args, **kwargs):
curPath = os.getcwd()
os.chdir(path)
result = callFunc(*args, **kwargs)
os.chdir(curPath)
return result
return wrapper_callFromPath
return decorator_callFromPath
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment