-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
69 lines (51 loc) · 1.62 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
66
67
68
69
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
main.py
MIT License (c) Faure Systems <dev at faure dot systems>
Room (xcape.io) plugin.
usage: python main.py [-h] [-s SERVER] [-p PORT] [-d] [-l LOGGER]
optional arguments:
-h, --help show this help message and exit
-s SERVER, --server SERVER
change MQTT server host
-p PORT, --port PORT change MQTT server port
-d, --debug set DEBUG log level
-l LOGGER, --logger LOGGER
use logging config file
To switch MQTT broker, kill the program and start again with new arguments.
"""
import paho.mqtt.client as mqtt
import os, sys, platform, signal, uuid
os.chdir(os.path.dirname(os.path.abspath(__file__)))
sys.path.append('./core')
from AudioBox import AudioBox
from Singleton import Singleton, SingletonException
me = None
try:
me = Singleton()
except SingletonException:
sys.exit(-1)
except BaseException as e:
print(e)
mqtt_client = mqtt.Client(uuid.uuid4().urn, clean_session=True, userdata=None)
applet = AudioBox(sys.argv, mqtt_client, debugging_mqtt=True)
if applet.logger:
applet.logger.info(applet.tr("Session started"))
# Assign handler for process exit (shows not effect on Windows in debug here)
signal.signal(signal.SIGTERM, applet.quit)
signal.signal(signal.SIGINT, applet.quit)
if platform.system() != 'Windows':
signal.signal(signal.SIGHUP, applet.quit)
signal.signal(signal.SIGQUIT, applet.quit)
applet.start()
rc = applet.exec_()
try:
mqtt_client.disconnect()
mqtt_client.loop_stop()
except:
pass
if applet.logger:
applet._logger.info(applet.tr("Session done"))
del me
sys.exit(rc)