mirror of
https://github.com/mwpenny/portal64-still-alive.git
synced 2024-10-20 10:37:37 -04:00
37 lines
988 B
Python
37 lines
988 B
Python
|
#!/usr/bin/env python3
|
||
|
|
||
|
import subprocess
|
||
|
import os
|
||
|
import shlex
|
||
|
import sys
|
||
|
|
||
|
# Arguments to commands for converting assets are stored in text files
|
||
|
#
|
||
|
# This helper script allows calling the commands with the arguments from
|
||
|
# such files in a cross-platform way.
|
||
|
|
||
|
if __name__ == "__main__":
|
||
|
if len(sys.argv) != 5:
|
||
|
print("Runs a specified command with the given input and output file paths")
|
||
|
print("The command's arguments are read from a file")
|
||
|
print()
|
||
|
print(f"Usage: {sys.argv[0]} COMMAND INPUT_FILE ARGS_FILE OUTPUT_FILE")
|
||
|
sys.exit(1)
|
||
|
|
||
|
command, input_file, args_file, output_file = sys.argv[1:]
|
||
|
|
||
|
output_parent_dir = os.path.dirname(output_file)
|
||
|
if output_parent_dir:
|
||
|
os.makedirs(output_parent_dir, exist_ok=True)
|
||
|
|
||
|
with open(args_file) as f:
|
||
|
args = shlex.split(f.read().strip())
|
||
|
|
||
|
rc = subprocess.run([
|
||
|
command,
|
||
|
input_file,
|
||
|
*args,
|
||
|
output_file
|
||
|
])
|
||
|
sys.exit(rc.returncode)
|