diff --git a/VERSION b/VERSION index e6adf3f..ea2303b 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.4 \ No newline at end of file +0.5 \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index 2b1adc6..c70d0c7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -15,9 +15,7 @@ classifiers = [ "License :: OSI Approved :: CeCILL-C", "Operating System :: OS Independent", ] -dependencies = [ - "systemd-python", -] +dependencies = [ ] dynamic = ["version"] [project.urls] diff --git a/src/appengine/__init__.py b/src/appengine/__init__.py index f4e2bd7..ca9ae07 100644 --- a/src/appengine/__init__.py +++ b/src/appengine/__init__.py @@ -5,7 +5,6 @@ import sys import traceback from configparser import ConfigParser import logging -from systemd import journal import inspect from enum import Enum, auto import signal @@ -49,6 +48,8 @@ class AppEngineException(Exception): def __init__(self, error: AEErrs, mesg=None) -> None: if mesg is None: self.mesg = str(error) + else: + self.mesg = mesg super().__init__(self.mesg) self.value = error.value @@ -106,8 +107,8 @@ class Commands(Thread): self.stopped = True def free(self): - """ Virtual method used to clean resources for threaded Commands - when they are stopped. + """ Virtual method used to clean resources for all Commands + when the application is exited. """ pass @@ -300,7 +301,11 @@ class CommandsLoader: obj = None for n, c in members: if issubclass(c, Commands) and (n != "Commands"): - obj = c(conf, self.log) + try: + obj = c(conf, self.log) + except: + self.log.error(f"The object '{c.__name__}' could not be instantiated.") + continue obj.log = self.log obj.lock = self.lock obj.stop_all_event = self.stop_event @@ -315,9 +320,15 @@ class CommandsLoader: def _load_dependencies(self): for k, v in self.cmods.items(): if hasattr(v, "dependencies"): - for p in v.dependencies: - if p in self.cmods.keys(): - setattr(v, p, self.cmods[p]) + deps = v.dependencies + # dependencies can be a list or dictionary + 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: self.log.error( 'Dependency "{}" of module "{}" could not be satisfied'.format( @@ -343,8 +354,7 @@ class CommandsLoader: def free(self): for k, v in self.cmods.items(): - if v.threaded: - v.free() + v.free() class AppEngine: @@ -396,12 +406,8 @@ class AppEngine: if is_writeable: self.log.addHandler(logging.FileHandler(fname)) else: - self.log.addHandler(journal.JournalHandler()) self.log.error('No write permissions: "{}"'.format(fname)) - else: - self.log.addHandler(journal.JournalHandler()) - def exec(self, modpath: str = ""): self.cl = CommandsLoader(self.stop_event, self.conf, self.log, modpath) self.cl.start()