Projekt

Obecné

Profil

Stáhnout (1.34 KB) Statistiky
| Větev: | Tag: | Revize:
1 bba28c53 silhavyj
import logging
2 0b96f10c Pultak
import logging.config
3
from os.path import exists
4 f7fb8759 silhavyj
from threading import Thread
5 bba28c53 silhavyj
from tendo import singleton
6 fddc9b6d silhavyj
from sys import exit
7 bba28c53 silhavyj
8 e22c7a67 silhavyj
from config_manager import logger_config
9 f7fb8759 silhavyj
from usb_detector.detector import register_listener, usb_detector_run
10
from usb_detector.event_listener import usb_connected_callback, usb_disconnected_callback
11 76b68bb9 silhavyj
from api_client import api_client_run
12 f7fb8759 silhavyj
13 e22c7a67 silhavyj
14 0b96f10c Pultak
def init_logging():
15
    if exists(logger_config):
16
        logging.config.fileConfig(fname=logger_config)
17
    else:
18
        print(f"Cant find logger configuration \"{logger_config}\"! Please specify valid path or define new.")
19
        exit(1)
20
21 bba28c53 silhavyj
22
if __name__ == "__main__":
23 fddc9b6d silhavyj
    try:
24
        app_instance = singleton.SingleInstance()
25
    except singleton.SingleInstanceException:
26
        exit(1)
27
28 0b96f10c Pultak
    init_logging()
29 bba28c53 silhavyj
30 f7fb8759 silhavyj
    register_listener(callback=usb_connected_callback, connected=True)
31
    register_listener(callback=usb_disconnected_callback, connected=False)
32
33
    usb_detector_thread = Thread(target=usb_detector_run)
34
    usb_detector_thread.setDaemon(True)
35 76b68bb9 silhavyj
36
    api_thread = Thread(target=api_client_run)
37
    api_thread.setDaemon(True)
38
39 0b96f10c Pultak
    logging.info('starting USB detector.')
40 f7fb8759 silhavyj
    usb_detector_thread.start()
41 0b96f10c Pultak
42
    logging.info('starting API communication manager.')
43 76b68bb9 silhavyj
    api_thread.start()
44 bba28c53 silhavyj
45 f7fb8759 silhavyj
    usb_detector_thread.join()
46 76b68bb9 silhavyj
    api_thread.join()
47 0b96f10c Pultak
48
    logging.info('application exit.')