forked from flatsiedatsie/power-settings
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
37 lines (26 loc) · 930 Bytes
/
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
"""Power settings add-on 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'))
#from pkg.power_settings import PowerSettingsAdapter # noqa
from pkg.power_settings import PowerSettingsAPIHandler # noqa
_HANDLER = None
print = functools.partial(print, flush=True)
def cleanup(signum, frame):
"""Clean up any resources before exiting."""
if _HANDLER is not None:
_HANDLER.close_proxy()
sys.exit(0)
if __name__ == '__main__':
signal.signal(signal.SIGINT, cleanup)
signal.signal(signal.SIGTERM, cleanup)
#_HANDLER = PowerSettingsAdapter(verbose=True)
_HANDLER = PowerSettingsAPIHandler(verbose=True)
# Wait until the proxy stops running, indicating that the gateway shut us
# down.
while _HANDLER.proxy_running():
time.sleep(2)