From a9111c724148634486524f3744c3bbe039f3cc1d Mon Sep 17 00:00:00 2001 From: jesopo Date: Mon, 14 Oct 2019 12:55:32 +0100 Subject: add ModuleManager.try_reload_modules(), to try reloading in a transaction if any of the modules fails to reload, rollback and use the already loaded modules. closes #179 --- modules/modules.py | 23 ++++------------------- 1 file changed, 4 insertions(+), 19 deletions(-) (limited to 'modules/modules.py') diff --git a/modules/modules.py b/modules/modules.py index 25a2c289..cac145ba 100644 --- a/modules/modules.py +++ b/modules/modules.py @@ -71,26 +71,11 @@ class Module(ModuleManager.BaseModule): :help: Reload all modules :permission: reload-all-modules """ - success = [] - fail = [] - for name in list(self.bot.modules.modules.keys()): - try: - self.bot.modules.unload_module(name) - except ModuleManager.ModuleWarning: - continue - except: - fail.append(name) - load_success, load_fail = self.bot.load_modules(safe=True) - success.extend(load_success) - fail.extend(load_fail) - - if success and fail: - event["stdout"].write("Reloaded %d modules, %d failed" % ( - len(success), len(fail))) - elif fail: - event["stdout"].write("Failed to reload all modules") + result = self.bot.try_reload_modules() + if result.success: + event["stdout"].write(result.message) else: - event["stdout"].write("Reloaded %d modules" % len(success)) + event["stderr"].write(result.message) @utils.hook("received.command.enablemodule", min_args=1) def enable(self, event): -- cgit v1.3.1-10-gc9f91