-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
78 lines (56 loc) · 1.88 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
70
71
72
73
74
75
76
77
78
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
main.py
MIT License (c) Faure Systems <dev at faure dot systems>
Applet to control remotely a Raspberry running Teletext Props.
usage: python main.py [-h] [-s SERVER] [-p PORT] [-d] [-l LOGGER]
optional arguments:
-h, --help show this help message and exit
-f, --french run in French
-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.
"""
from PyQt5.QtCore import QUuid
from PyQt5.QtGui import QIcon
import paho.mqtt.client as mqtt
import os, sys, platform, signal
from PluginApplet import PluginApplet
from Singleton import Singleton, SingletonException
me = None
try:
me = Singleton()
except SingletonException:
sys.exit(-1)
except BaseException as e:
print(e)
os.chdir(os.path.dirname(os.path.abspath(__file__)))
clientid = "Xcape/Plugin/" + QUuid.createUuid().toString()
mqtt_client = mqtt.Client(clientid, clean_session=True, userdata=None)
applet = PluginApplet(sys.argv, mqtt_client, debugging_mqtt=True)
applet.setApplicationDisplayName("Room")
applet.setWindowIcon(QIcon('./teletext-on.svg'));
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)