Skip to content

Commit

Permalink
Merge branch 'hotfixes-py3'
Browse files Browse the repository at this point in the history
  • Loading branch information
neoclust committed Aug 11, 2024
2 parents 5561076 + 5b2c2d9 commit 0265dcf
Show file tree
Hide file tree
Showing 10 changed files with 235 additions and 121 deletions.
37 changes: 31 additions & 6 deletions kiosk_interface/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from PyQt6.QtWidgets import QApplication
from PyQt6.QtCore import QCoreApplication
from PyQt6.QtGui import QIcon
import logging

try:
# Import for unit tests
Expand All @@ -48,10 +49,10 @@
class Application(QApplication):
"""Generate the main app object"""

def __init__(self):
def __init__(self, conf):
"""Initialize the object"""

super().__init__(sys.argv) # Initialize the Qapplication
self.log = logging.getLogger()

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

if sys.platform.startswith("win"):
pidfile = os.path.join("C:\\", "windows", "temp", "kiosk.pid")
else:
pidfile = os.path.join("/", "tmp", "kiosk.pid")

with open(pidfile, "w") as pidfb:
pidfb.write("%s"%os.getpid())
pidfb.close()

# Notify the application when something is happening
self.notifier = Notifier()
# Action launched when the kiosk emit a notification
Expand All @@ -85,13 +95,14 @@ def __init__(self):
self.translate = QCoreApplication.translate

# Keep the config parameters in memory
self.parameters = ConfParameter()
self.parameters = conf

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

self.logger("info", "Initialization")
self.log.info("Kiosk initialization")
# The mechanics are launched here
self.notifier.app_launched.emit()

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

def run(self):
"""Launch the main loop"""
self.exec()
try:
self.exec()
except Exception as err:
self.log.error("Error during execution: %s" % err)

# Associate a unique sender. This module send messages to AM
def send(self, message):
messenger = MessengerToAM(self)
messenger.send(message)
try:
messenger.send(message)
except Exception as err:
self.log.error("Error during sending %s : %s" % (message, err))

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


if __name__ == "__main__":
app = Application()
conf = ConfParameter()
format = "%(asctime)s - %(levelname)s -(LAUNCHER)%(message)s"
formatter = logging.Formatter(format)
logdir = os.path.dirname(conf.logfilename())
if os.path.isdir(logdir):
os.makedirs(logdir, exist_ok=True)
logging.basicConfig(level=conf.log_level, format=format, filename=conf.logfilename(), filemode="a")

app = Application(conf)
app.send_ping()
app.run()
7 changes: 0 additions & 7 deletions kiosk_interface/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,6 @@ def action_message_received_from_am(self, message="{}"):
}
}
"""
if self.app.kiosk.tab_notification is not None:
self.app.kiosk.tab_notification.add_notification(
self.app.message["data"]["message"]
)
else:
print(self.app.message["message"])

if "status" in self.app.message["data"] and "stat" in self.app.message["data"]:
uuid = self.app.message["data"]["path"].split("/")
uuid = uuid[-1]
Expand Down
45 changes: 45 additions & 0 deletions kiosk_interface/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,48 @@ def __init__(self, typeconf="machine"):

self.width = 650
self.height = 550

self.log_level = self.get_loglevel_from_str("INFO")
if config.has_option("global", "log_level"):
self.log_level = self.get_loglevel_from_str(config.get("global", "log_level"))


def get_loglevel_from_str(self, levelstring):
strlevel = levelstring.upper()
if strlevel in ["CRITICAL", "FATAL"]:
return 50
elif strlevel == "ERROR":
return 40
elif strlevel in ["WARNING", "WARN"]:
return 30
elif strlevel == "INFO":
return 20
elif strlevel == "DEBUG":
return 10
elif strlevel == "NOTSET":
return 0
elif strlevel in ["LOG", "DEBUGPULSE"]:
return 25
else:
return 20

def logfilename(self):
"""
Function defining where the log file is located.
configuration file for the type of machifne and the Operating System
Returns:
Return the log file path
"""
logfilenameparameter = "kiosk-interface.log"

if sys.platform.startswith("linux"):
fileconf = os.path.join(os.path.expanduser("~"), logfilenameparameter)
elif sys.platform.startswith("win"):
fileconf = os.path.join(
os.path.expanduser("~"), logfilenameparameter
)
elif sys.platform.startswith("darwin"):
fileconf = os.path.join(os.path.expanduser("~"), logfilenameparameter)
return fileconf
Loading

0 comments on commit 0265dcf

Please sign in to comment.