This commit is contained in:
François Dausseur
2025-10-28 11:37:14 +01:00
3 changed files with 21 additions and 17 deletions

View File

@@ -1 +1 @@
0.4 0.5

View File

@@ -15,9 +15,7 @@ classifiers = [
"License :: OSI Approved :: CeCILL-C", "License :: OSI Approved :: CeCILL-C",
"Operating System :: OS Independent", "Operating System :: OS Independent",
] ]
dependencies = [ dependencies = [ ]
"systemd-python",
]
dynamic = ["version"] dynamic = ["version"]
[project.urls] [project.urls]

View File

@@ -5,7 +5,6 @@ import sys
import traceback import traceback
from configparser import ConfigParser from configparser import ConfigParser
import logging import logging
from systemd import journal
import inspect import inspect
from enum import Enum, auto from enum import Enum, auto
import signal import signal
@@ -49,6 +48,8 @@ class AppEngineException(Exception):
def __init__(self, error: AEErrs, mesg=None) -> None: def __init__(self, error: AEErrs, mesg=None) -> None:
if mesg is None: if mesg is None:
self.mesg = str(error) self.mesg = str(error)
else:
self.mesg = mesg
super().__init__(self.mesg) super().__init__(self.mesg)
self.value = error.value self.value = error.value
@@ -106,8 +107,8 @@ class Commands(Thread):
self.stopped = True self.stopped = True
def free(self): def free(self):
""" Virtual method used to clean resources for threaded Commands """ Virtual method used to clean resources for all Commands
when they are stopped. when the application is exited.
""" """
pass pass
@@ -300,7 +301,11 @@ class CommandsLoader:
obj = None obj = None
for n, c in members: for n, c in members:
if issubclass(c, Commands) and (n != "Commands"): if issubclass(c, Commands) and (n != "Commands"):
try:
obj = c(conf, self.log) obj = c(conf, self.log)
except:
self.log.error(f"The object '{c.__name__}' could not be instantiated.")
continue
obj.log = self.log obj.log = self.log
obj.lock = self.lock obj.lock = self.lock
obj.stop_all_event = self.stop_event obj.stop_all_event = self.stop_event
@@ -315,9 +320,15 @@ class CommandsLoader:
def _load_dependencies(self): def _load_dependencies(self):
for k, v in self.cmods.items(): for k, v in self.cmods.items():
if hasattr(v, "dependencies"): if hasattr(v, "dependencies"):
for p in v.dependencies: deps = v.dependencies
if p in self.cmods.keys(): # dependencies can be a list or dictionary
setattr(v, p, self.cmods[p]) if isinstance(v.dependencies, list):
deps = {}
for d in v.dependencies:
deps[d] = d
for p, pv in deps.items():
if pv in self.cmods.keys():
setattr(v, p, self.cmods[pv])
else: else:
self.log.error( self.log.error(
'Dependency "{}" of module "{}" could not be satisfied'.format( 'Dependency "{}" of module "{}" could not be satisfied'.format(
@@ -343,7 +354,6 @@ class CommandsLoader:
def free(self): def free(self):
for k, v in self.cmods.items(): for k, v in self.cmods.items():
if v.threaded:
v.free() v.free()
@@ -396,12 +406,8 @@ class AppEngine:
if is_writeable: if is_writeable:
self.log.addHandler(logging.FileHandler(fname)) self.log.addHandler(logging.FileHandler(fname))
else: else:
self.log.addHandler(journal.JournalHandler())
self.log.error('No write permissions: "{}"'.format(fname)) self.log.error('No write permissions: "{}"'.format(fname))
else:
self.log.addHandler(journal.JournalHandler())
def exec(self, modpath: str = ""): def exec(self, modpath: str = ""):
self.cl = CommandsLoader(self.stop_event, self.conf, self.log, modpath) self.cl = CommandsLoader(self.stop_event, self.conf, self.log, modpath)
self.cl.start() self.cl.start()