From 7319150e7c55ef758a78d29390fafd4e413e743c Mon Sep 17 00:00:00 2001 From: Matthias Date: Wed, 15 Sep 2021 07:26:30 +0200 Subject: [PATCH] refactor of load_plugin --- InvenTree/plugins/plugins.py | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/InvenTree/plugins/plugins.py b/InvenTree/plugins/plugins.py index f6b68112bc..8ebfcd7586 100644 --- a/InvenTree/plugins/plugins.py +++ b/InvenTree/plugins/plugins.py @@ -51,19 +51,30 @@ def get_plugins(pkg, baseclass): return plugins -def load_action_plugins(): - """ - Return a list of all registered action plugins +def load_plugins(name:str, module, cls): + """general function to load a plugin class + + :param name: name of the plugin for logs + :type name: str + :param module: module from which the plugins should be loaded + :return: class of the to-be-loaded plugin """ - logger.debug("Loading action plugins") + logger.debug(f"Loading {name} plugins") - plugins = get_plugins(action, ActionPlugin) + plugins = get_plugins(module, cls) if len(plugins) > 0: - logger.info("Discovered {n} action plugins:".format(n=len(plugins))) + logger.info(f"Discovered {len(plugins)} {name} plugins:") for ap in plugins: logger.debug(" - {ap}".format(ap=ap.PLUGIN_NAME)) return plugins + + +def load_action_plugins(): + """ + Return a list of all registered action plugins + """ + return load_plugins('action', action, ActionPlugin)