5 Commits
v0.4 ... v0.6

Author SHA1 Message Date
François Dausseur
5a60e47c12 rev 0.6 2025-10-28 11:48:17 +01:00
François Dausseur
355915e9c1 Merge branch 'main' of https://git.beafrancois.fr/Foue-opensource/pyappengine 2025-10-28 11:37:14 +01:00
François Dausseur
0da36439a6 management of help functions improved. 2025-10-28 11:37:10 +01:00
François Dausseur
3d402db2c2 free not limited to threaded modules. modified the modules dependencies management. 2025-09-20 16:33:21 +02:00
François Dausseur
de04b2b3b9 robustness. 2025-04-30 17:39:35 +02:00
2 changed files with 42 additions and 10 deletions

View File

@@ -1 +1 @@
0.4
0.6

View File

@@ -48,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
@@ -105,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
@@ -174,7 +176,28 @@ class Commands(Thread):
if module == "":
if method == 'help':
return self.list_modules()
# No argument was given to the help function
if len(args) == 0 and len(kwargs) == 0:
msg = "Type 'help <module>' to have the list of module's functions.\n"
msg += "Type 'help <module>.<function>' to documentation of a specific function.\n"
success, ret = self.list_modules()
return success, msg + ret
else:
# 1 argument has been provided
if len(args) > 0:
arg = args[0]
else:
arg = list(kwargs.keys())[0]
spl = arg.split(".", 1)
# help <module>
if len(spl) == 1:
module = arg
# help <module>.<method>
else:
module = spl[0]
args = [spl[1]]
kwargs = {}
else:
module = self.defmod
@@ -278,7 +301,11 @@ class CommandsLoader:
obj = None
for n, c in members:
if issubclass(c, Commands) and (n != "Commands"):
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
@@ -293,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(
@@ -321,7 +354,6 @@ class CommandsLoader:
def free(self):
for k, v in self.cmods.items():
if v.threaded:
v.free()