-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.py
52 lines (39 loc) · 1.33 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
40
41
42
43
44
45
46
47
48
49
50
51
52
import json
import signal
import threading
from argparse import ArgumentParser, ArgumentDefaultsHelpFormatter, Namespace
from application import Application
def get_execution_arguments() -> Namespace:
parser = ArgumentParser(
prog='main.py',
description='Starts the application',
formatter_class=ArgumentDefaultsHelpFormatter
)
parser.add_argument(
'--config',
help='Path to the configuration file',
type=str,
default='config/configuration.json'
)
return parser.parse_args()
def get_config_path(args: Namespace) -> str:
return args.config
def get_config_data(config_path:str):
configuration_file = open(config_path, 'r', encoding='utf-8')
config_data = json.load(configuration_file)
configuration_file.close()
return config_data
if __name__ == '__main__':
exec_args = get_execution_arguments()
config_path = get_config_path(exec_args)
config_data = get_config_data(config_path)
app = Application(config_data)
def signal_handler(sig, frame):
print('Will dispose application')
stop_event.set()
signal.signal(signal.SIGINT, signal_handler)
stop_event = threading.Event()
# Use a loop to poll the event status
while not stop_event.is_set():
stop_event.wait(0.1) # Check every 100ms
app.dispose()