-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathhpr-sim.py
executable file
·81 lines (57 loc) · 2.11 KB
/
hpr-sim.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/usr/bin/env python3
# System modules
import os
import sys
import argparse
import pathlib
import multiprocessing as mp
import colorama
# Path modifications
paths = ["build/src", "src/exec", "src/gui", "src/preproc", "src/postproc", "src/util"]
for item in paths:
addPath = pathlib.Path(__file__).parent / item
sys.path.append(addPath.resolve().as_posix())
# Project modules
import exec
import gui_main
import postproc_flight
import util_yaml
import util_misc
#------------------------------------------------------------------------------#
def cli_intro():
colorama.init()
print(colorama.Fore.CYAN)
print(f"{util_misc.get_timestamp()}")
print(f"hpr-sim v{util_misc.get_version()}")
print(colorama.Style.RESET_ALL)
#------------------------------------------------------------------------------#
if __name__ == "__main__":
# Multiprocessing support for PyInstaller
mp.freeze_support()
# Parse CLI arguments
parser = argparse.ArgumentParser()
parser.add_argument("-i", "--input", type=str, help="Input file; if none given, user interface will launch")
parser.add_argument("-o", "--output", type=str, help="Output directory; if none given, assumed to be output/")
args = parser.parse_args()
# Run program
if args.input is None:
# Run GUI
gui_main.exec()
else:
# Run CLI (headless)
util_misc.set_timestamp()
cli_intro()
inputPath = pathlib.Path(args.input)
if args.output is None:
outputPath = pathlib.Path("output")
print(colorama.Fore.RED, end='')
print(f"No output directory given, using: {outputPath.resolve()}")
print(colorama.Style.RESET_ALL)
if not os.path.exists(outputPath):
os.mkdir(outputPath)
else:
outputPath = pathlib.Path(args.output)
outputPath = outputPath / inputPath.stem # Add subdirectory
print(f"Reading input file: {colorama.Fore.YELLOW}{inputPath.resolve()}{colorama.Style.RESET_ALL}")
inputParams = util_yaml.load(inputPath)
exec.run(inputParams, outputPath)