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