Skip to content

Commit 0265dcf

Browse files
committed
Merge branch 'hotfixes-py3'
2 parents 5561076 + 5b2c2d9 commit 0265dcf

File tree

10 files changed

+235
-121
lines changed

10 files changed

+235
-121
lines changed

kiosk_interface/__main__.py

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
from PyQt6.QtWidgets import QApplication
2727
from PyQt6.QtCore import QCoreApplication
2828
from PyQt6.QtGui import QIcon
29+
import logging
2930

3031
try:
3132
# Import for unit tests
@@ -48,10 +49,10 @@
4849
class Application(QApplication):
4950
"""Generate the main app object"""
5051

51-
def __init__(self):
52+
def __init__(self, conf):
5253
"""Initialize the object"""
53-
5454
super().__init__(sys.argv) # Initialize the Qapplication
55+
self.log = logging.getLogger()
5556

5657
# To add an event :
5758
# 1 - In Notifier create the signal
@@ -71,6 +72,15 @@ def __init__(self):
7172
self.datasdir = os.path.join(self.rootdir, "datas")
7273
self.viewsdir = os.path.join(self.rootdir, "views")
7374

75+
if sys.platform.startswith("win"):
76+
pidfile = os.path.join("C:\\", "windows", "temp", "kiosk.pid")
77+
else:
78+
pidfile = os.path.join("/", "tmp", "kiosk.pid")
79+
80+
with open(pidfile, "w") as pidfb:
81+
pidfb.write("%s"%os.getpid())
82+
pidfb.close()
83+
7484
# Notify the application when something is happening
7585
self.notifier = Notifier()
7686
# Action launched when the kiosk emit a notification
@@ -85,13 +95,14 @@ def __init__(self):
8595
self.translate = QCoreApplication.translate
8696

8797
# Keep the config parameters in memory
88-
self.parameters = ConfParameter()
98+
self.parameters = conf
8999

90100
# Socket server. It is always running. This module listen and wait the
91101
# messages from AM
92102
self.receiver = MessengerFromAM(self)
93103

94104
self.logger("info", "Initialization")
105+
self.log.info("Kiosk initialization")
95106
# The mechanics are launched here
96107
self.notifier.app_launched.emit()
97108

@@ -111,12 +122,18 @@ def __init__(self):
111122

112123
def run(self):
113124
"""Launch the main loop"""
114-
self.exec()
125+
try:
126+
self.exec()
127+
except Exception as err:
128+
self.log.error("Error during execution: %s" % err)
115129

116130
# Associate a unique sender. This module send messages to AM
117131
def send(self, message):
118132
messenger = MessengerToAM(self)
119-
messenger.send(message)
133+
try:
134+
messenger.send(message)
135+
except Exception as err:
136+
self.log.error("Error during sending %s : %s" % (message, err))
120137

121138
def logger(self, type, msg):
122139
"""Send log message to Agent Machine.
@@ -144,6 +161,14 @@ def send_pong(self):
144161

145162

146163
if __name__ == "__main__":
147-
app = Application()
164+
conf = ConfParameter()
165+
format = "%(asctime)s - %(levelname)s -(LAUNCHER)%(message)s"
166+
formatter = logging.Formatter(format)
167+
logdir = os.path.dirname(conf.logfilename())
168+
if os.path.isdir(logdir):
169+
os.makedirs(logdir, exist_ok=True)
170+
logging.basicConfig(level=conf.log_level, format=format, filename=conf.logfilename(), filemode="a")
171+
172+
app = Application(conf)
148173
app.send_ping()
149174
app.run()

kiosk_interface/actions.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -138,13 +138,6 @@ def action_message_received_from_am(self, message="{}"):
138138
}
139139
}
140140
"""
141-
if self.app.kiosk.tab_notification is not None:
142-
self.app.kiosk.tab_notification.add_notification(
143-
self.app.message["data"]["message"]
144-
)
145-
else:
146-
print(self.app.message["message"])
147-
148141
if "status" in self.app.message["data"] and "stat" in self.app.message["data"]:
149142
uuid = self.app.message["data"]["path"].split("/")
150143
uuid = uuid[-1]

kiosk_interface/config.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,3 +94,48 @@ def __init__(self, typeconf="machine"):
9494

9595
self.width = 650
9696
self.height = 550
97+
98+
self.log_level = self.get_loglevel_from_str("INFO")
99+
if config.has_option("global", "log_level"):
100+
self.log_level = self.get_loglevel_from_str(config.get("global", "log_level"))
101+
102+
103+
def get_loglevel_from_str(self, levelstring):
104+
strlevel = levelstring.upper()
105+
if strlevel in ["CRITICAL", "FATAL"]:
106+
return 50
107+
elif strlevel == "ERROR":
108+
return 40
109+
elif strlevel in ["WARNING", "WARN"]:
110+
return 30
111+
elif strlevel == "INFO":
112+
return 20
113+
elif strlevel == "DEBUG":
114+
return 10
115+
elif strlevel == "NOTSET":
116+
return 0
117+
elif strlevel in ["LOG", "DEBUGPULSE"]:
118+
return 25
119+
else:
120+
return 20
121+
122+
def logfilename(self):
123+
"""
124+
Function defining where the log file is located.
125+
configuration file for the type of machifne and the Operating System
126+
127+
Returns:
128+
Return the log file path
129+
130+
"""
131+
logfilenameparameter = "kiosk-interface.log"
132+
133+
if sys.platform.startswith("linux"):
134+
fileconf = os.path.join(os.path.expanduser("~"), logfilenameparameter)
135+
elif sys.platform.startswith("win"):
136+
fileconf = os.path.join(
137+
os.path.expanduser("~"), logfilenameparameter
138+
)
139+
elif sys.platform.startswith("darwin"):
140+
fileconf = os.path.join(os.path.expanduser("~"), logfilenameparameter)
141+
return fileconf

0 commit comments

Comments
 (0)