Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5a60e47c12 | ||
|
|
355915e9c1 | ||
|
|
0da36439a6 | ||
|
|
3d402db2c2 | ||
|
|
de04b2b3b9 |
@@ -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"):
|
||||
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
|
||||
@@ -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,8 +354,7 @@ class CommandsLoader:
|
||||
|
||||
def free(self):
|
||||
for k, v in self.cmods.items():
|
||||
if v.threaded:
|
||||
v.free()
|
||||
v.free()
|
||||
|
||||
|
||||
class AppEngine:
|
||||
|
||||
Reference in New Issue
Block a user