-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapplication.py
More file actions
executable file
·127 lines (104 loc) · 4.43 KB
/
application.py
File metadata and controls
executable file
·127 lines (104 loc) · 4.43 KB
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#!python3
from utils import log_utils
import logging
import os
import sys
import argparse
import traceback
from functools import reduce
import operator
import matplotlib
import git
from flow import Flow
# Fix Ctrl+C
import signal
signal.signal(signal.SIGINT, signal.SIG_DFL)
matplotlib.use('agg')
logger = logging.getLogger("application")
def version_check() -> None:
logger.info("Running Version Check...")
try:
repo = git.Repo(os.path.dirname(__file__))
repo.remotes.origin.fetch()
local_commit = repo.head.commit
logger.info(f"Detected local Electrical Testing GUI commit {local_commit}")
remote_commit = repo.remotes.origin.refs[repo.active_branch.name].commit
if local_commit == remote_commit:
logger.info("You are up-to-date!")
else:
logger.critical("You are not running the latest version of the GUI.")
logger.critical(f"Remote branch is at {remote_commit}")
logger.critical("Fetch the latest version, or run with --skip-version-check")
sys.exit(1)
except Exception as e:
logger.critical(f"Version check failed with {e}\n{traceback.format_exc()}")
logger.critical("Fetch the latest version, or run with --skip-version-check")
sys.exit(1)
if __name__ == "__main__":
log_utils.setup_logging()
logger.info(f"Starting Electrical Testing GUI with arguments {sys.argv}")
parser = argparse.ArgumentParser(
prog="python application.py",
description="Hexaboard testing GUI",
formatter_class=argparse.RawTextHelpFormatter
)
# GUI Only
parser.add_argument('-v', '--vertical', action='store_true', help='Use the vertical GUI mode')
parser.add_argument('-W', '--no-watcher', action='store_true', help="Run without the watcher (gui frontend only)")
# CLI Only
parser.add_argument('-Q', '--quiet', action='store_true', help="Run without user input (cli frontend only)")
# Global
parser.add_argument('-d', '--debug', action='store_true', help="Enables Debug Logging")
parser.add_argument('-S', '--skip-version-check', action='store_true', help="Skips the version check")
parser.add_argument('-F', '--frontend', type=str, choices=["gui", "cli", "web"], default="gui", help="Pick which frontend to use")
parser.add_argument(
'-p', '--parameters', nargs='+', action='append',
help="\n".join([
"specify the relative path to a parameters yaml file to use",
"each parameters file should specify a workflow file",
"parameters will be loaded from the parameters file and applied to the workflow file"
])
)
parser.add_argument(
'-w', '--workflow', nargs='+', action='append',
help="\n".join([
"specify the relative path to a workflow yaml file to use",
"this should be an untemplated yaml file"
])
)
args = parser.parse_args()
if args.debug:
logging.getLogger().setLevel(logging.DEBUG)
logger.debug(f"Running with args {args}")
if not args.skip_version_check:
version_check()
else:
logger.critical("Version check skipped!")
flows = []
if args.parameters:
parameter_files = reduce(operator.concat, args.parameters)
flows += [Flow(parameters_file=file) for file in parameter_files]
if args.workflow:
workflow_files = reduce(operator.concat, args.workflow)
flows += [Flow(workflow_file=file) for file in workflow_files]
logger.debug(f"Using workflows {flows}")
if args.frontend == "gui":
if len(flows) == 0:
logger.critical("At least one parameters or workflow file is required! See --help for more information.")
else:
# Import here to avoid loading qt if not used
# Qt requires tons of libraries to be installed - the docker file doesn't have any
from frontends.gui import gui
gui.run(args, flows)
elif args.frontend == "cli":
if len(flows) != 1:
logger.critical("No-GUI requires exactly one parameters or workflow file. See --help for more information.")
else:
from frontends import nogui
nogui.run(flows[0], args.quiet)
elif args.frontend == "web":
# Similarly, don't require a flask dependency if not using web
from frontends import web
web.run()
else:
raise ValueError(f"Invalid frontend {args.frontend}")