From 3da55d8608c3b034fbd08c3176eca349b66c4d89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Dausseur?= Date: Fri, 28 Apr 2023 15:32:34 +0200 Subject: [PATCH] Help is working --- src/pyappengine/__init__.py | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/pyappengine/__init__.py b/src/pyappengine/__init__.py index 3a3f1a6..acf5f18 100644 --- a/src/pyappengine/__init__.py +++ b/src/pyappengine/__init__.py @@ -104,9 +104,9 @@ class Commands(Thread): def list_modules(self): success = True - ret = "" + ret = "List of modules:\n" for module in self.cmods.keys(): - ret = ret + module + "\n" + ret = ret + " " + module + "\n" return success, ret.strip() def _execute_command(self, method: str, *args, **kwargs) -> tuple: @@ -156,14 +156,17 @@ class Commands(Thread): success = False if module == "": - module = self.config["default"] + if method == 'help': + return self.list_modules() + else: + module = self.defmod if not (module in self.cmods.keys()): m = module.replace("_", "-") if not (m in self.cmods.keys()): ret = 'module "{}" not found'.format(module) self.log.error(ret) - return success, ret + return success, (AEErrs.INVALID_REQUEST.value, ret) return self.cmods[module]._execute_command(method, *args, **kwargs) @@ -177,12 +180,12 @@ class Commands(Thread): if len(args) == 0: 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: - ret = ret + m[0][len("cmd_") :] + "\n" + ret = ret + m[0][len(self.precmd):] + "\n" else: if isinstance(args[0], str): - cmd = "cmd_" + args[0] + cmd = self.precmd + args[0] c = getattr(self, cmd, None) if c: r = inspect.getdoc(c) @@ -227,7 +230,7 @@ class CommandsLoader: if not obj is None: nmod = obj.nickname if nmod is None: - nmod = (entry.name[:-3])[5:] + nmod = (entry.name[:-3])[len(self.precmds):] cmds.update({nmod: obj}) self.log.info('module "{}" loaded'.format(nmod)) else: @@ -242,8 +245,8 @@ class CommandsLoader: module = import_module(name) members = inspect.getmembers(module, inspect.isclass) conf = None - if name[5:] in self.config.sections(): - conf = self.config[name[5:]] + if name[len(self.precmds):] in self.config.sections(): + conf = self.config[name[len(self.precmds):]] obj = None for n, c in members: