-
Notifications
You must be signed in to change notification settings - Fork 6
/
main.py
48 lines (35 loc) · 1.14 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
"""Voco adapter and notifier for Candle controller."""
from os import path
import functools
import gateway_addon
import signal
import sys
import time
sys.path.append(path.join(path.dirname(path.abspath(__file__)), 'lib'))
if path.exists('/usr/lib/aarch64-linux-gnu'):
sys.path.append('/usr/lib/aarch64-linux-gnu')
from pkg.voco_adapter import VocoAdapter # noqa
_API_VERSION = {
'min': 2,
'max': 2,
}
_ADAPTER = None
print = functools.partial(print, flush=True)
def cleanup(signum, frame):
print("In cleanup function of main.py")
"""Clean up any resources before exiting."""
if _ADAPTER is not None:
_ADAPTER.close_proxy()
sys.exit(0)
if __name__ == '__main__':
if gateway_addon.API_VERSION < _API_VERSION['min'] or \
gateway_addon.API_VERSION > _API_VERSION['max']:
print('Unsupported API version.')
sys.exit(0)
signal.signal(signal.SIGINT, cleanup)
signal.signal(signal.SIGTERM, cleanup)
_ADAPTER = VocoAdapter(verbose=False)
# Wait until the proxy stops running, indicating that the gateway shut us
# down.
while _ADAPTER.proxy_running():
time.sleep(2)