Commit 4888a5af authored by Guillaume Seguin's avatar Guillaume Seguin

Add prepare_command helper to utils

parent 59ac3771
......@@ -96,13 +96,17 @@ def format_time(timestamp):
def format_duration(delta):
return str(datetime.timedelta(seconds = int(delta)))
def run_command(command, replaces = None, stdout = subprocess.STDOUT, stderr = subprocess.STDOUT, blocking = False):
def prepare_command(command, replaces = None):
command = shlex.split(command.replace("\\", "\\\\").encode())
if replaces is not None:
if replaces:
replaces["$python"] = sys.executable
for pattern, rep in replaces.items():
command = [bit.replace(pattern, rep) for bit in command]
command = [bit.encode() for bit in command]
return command
def run_command(command, replaces = None, stdout = subprocess.STDOUT, stderr = subprocess.STDOUT, blocking = False):
command = prepare_command(command, replaces)
if blocking:
return subprocess.call(command)
else:
......
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