-
-
Notifications
You must be signed in to change notification settings - Fork 41
/
main.py
65 lines (43 loc) · 1.37 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
53
54
55
56
57
58
59
60
61
62
63
64
65
from logging import handlers
import logging
import signal
import time
from datetime import datetime
from models.Configuration import readConfiguration
from models.HermesLedControl import HermesLedControl
formatter = logging.Formatter('%(asctime)s [%(threadName)s] - [%(levelname)s] - %(message)s')
_logger = logging.getLogger('HermesLedControl')
_logger.setLevel(logging.DEBUG)
date = int(datetime.now().strftime('%Y%m%d'))
handler = logging.FileHandler(filename='logs.log', mode='w')
rotatingHandler = handlers.RotatingFileHandler(filename=f'./logs/{date}-logs.log', mode='a', maxBytes=100000, backupCount=5)
streamHandler = logging.StreamHandler()
handler.setFormatter(formatter)
rotatingHandler.setFormatter(formatter)
streamHandler.setFormatter(formatter)
_logger.addHandler(handler)
_logger.addHandler(rotatingHandler)
_logger.addHandler(streamHandler)
def stopHandler(_signum, frame):
onStop()
def onStop():
global RUNNING
RUNNING = False
def main():
_logger.info('Starting Hermes Led Control version 3.0.4')
signal.signal(signal.SIGINT, stopHandler)
signal.signal(signal.SIGTERM, stopHandler)
args = readConfiguration()
slc = HermesLedControl(args)
slc.onStart()
try:
while RUNNING:
time.sleep(0.1)
except KeyboardInterrupt:
pass
finally:
_logger.info('Shutting down Hermes Led Control')
slc.onStop()
if __name__ == '__main__':
RUNNING = True
main()