Help is working

This commit is contained in:
François Dausseur
2023-04-28 15:32:34 +02:00
parent bfd6b875ec
commit 3da55d8608

View File

@@ -104,9 +104,9 @@ class Commands(Thread):
def list_modules(self): def list_modules(self):
success = True success = True
ret = "" ret = "List of modules:\n"
for module in self.cmods.keys(): for module in self.cmods.keys():
ret = ret + module + "\n" ret = ret + " " + module + "\n"
return success, ret.strip() return success, ret.strip()
def _execute_command(self, method: str, *args, **kwargs) -> tuple: def _execute_command(self, method: str, *args, **kwargs) -> tuple:
@@ -156,14 +156,17 @@ class Commands(Thread):
success = False success = False
if module == "": if module == "":
module = self.config["default"] if method == 'help':
return self.list_modules()
else:
module = self.defmod
if not (module in self.cmods.keys()): if not (module in self.cmods.keys()):
m = module.replace("_", "-") m = module.replace("_", "-")
if not (m in self.cmods.keys()): if not (m in self.cmods.keys()):
ret = 'module "{}" not found'.format(module) ret = 'module "{}" not found'.format(module)
self.log.error(ret) self.log.error(ret)
return success, ret return success, (AEErrs.INVALID_REQUEST.value, ret)
return self.cmods[module]._execute_command(method, *args, **kwargs) return self.cmods[module]._execute_command(method, *args, **kwargs)
@@ -177,12 +180,12 @@ class Commands(Thread):
if len(args) == 0: if len(args) == 0:
cmds = inspect.getmembers(self, predicate=inspect.ismethod) cmds = inspect.getmembers(self, predicate=inspect.ismethod)
cmds = [x for x in cmds if x[0].startswith("cmd_")] cmds = [x for x in cmds if x[0].startswith(self.precmd)]
for m in cmds: for m in cmds:
ret = ret + m[0][len("cmd_") :] + "\n" ret = ret + m[0][len(self.precmd):] + "\n"
else: else:
if isinstance(args[0], str): if isinstance(args[0], str):
cmd = "cmd_" + args[0] cmd = self.precmd + args[0]
c = getattr(self, cmd, None) c = getattr(self, cmd, None)
if c: if c:
r = inspect.getdoc(c) r = inspect.getdoc(c)
@@ -227,7 +230,7 @@ class CommandsLoader:
if not obj is None: if not obj is None:
nmod = obj.nickname nmod = obj.nickname
if nmod is None: if nmod is None:
nmod = (entry.name[:-3])[5:] nmod = (entry.name[:-3])[len(self.precmds):]
cmds.update({nmod: obj}) cmds.update({nmod: obj})
self.log.info('module "{}" loaded'.format(nmod)) self.log.info('module "{}" loaded'.format(nmod))
else: else:
@@ -242,8 +245,8 @@ class CommandsLoader:
module = import_module(name) module = import_module(name)
members = inspect.getmembers(module, inspect.isclass) members = inspect.getmembers(module, inspect.isclass)
conf = None conf = None
if name[5:] in self.config.sections(): if name[len(self.precmds):] in self.config.sections():
conf = self.config[name[5:]] conf = self.config[name[len(self.precmds):]]
obj = None obj = None
for n, c in members: for n, c in members: