-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
39 lines (33 loc) · 1.04 KB
/
main.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
"""User Interfaces for DPS Control"""
import sys
import os
from yaml import safe_load, YAMLError
from lib.dps_controller import DPSController
from ui.dps_cli import DPSCli
from ui.dps_gui import dps_gui
def main():
"""dps-control application"""
# Arguments
args: list[str] = sys.argv
# Try reading configuration
try:
config_file = 'dps_control.cfg'
bundle_dir = getattr(sys, '_MEIPASS', os.path.abspath(os.path.dirname(__file__)))
path_to_config = os.path.abspath(os.path.join(bundle_dir, config_file))
with open(path_to_config, 'r') as file:
conf = safe_load(file)
except YAMLError as error:
print(f'Error parsing configuration file {error}')
# Print config if debug
if conf['misc']['debug']:
print (conf)
# Create controller
controller = DPSController(conf)
# Start CLI if requested
if len(args) > 1 and args[1] == '--cli':
ui = DPSCli(controller)
ui.start()
else:
dps_gui(controller)
if __name__ == "__main__":
main()