From bb0e00b0da553da2a4cf3f758e36de95819e697c Mon Sep 17 00:00:00 2001 From: Bryce Boe Date: Sat, 10 Jul 2021 01:37:15 -0700 Subject: [PATCH] Reload all plugins in a repo `get_plugin_by_path` would only return the first plugin encountered in a repository. This change adds the method `get_plugins_by_path` which yields plugins as they are found. For backwards compatibility, I have not deleted the original `get_plugin_by_path` method, lest anyone use that method directly outside of this package. --- errbot/core_plugins/plugins.py | 18 +++++++++--------- errbot/plugin_manager.py | 5 +++++ 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/errbot/core_plugins/plugins.py b/errbot/core_plugins/plugins.py index 1653afddf..980431ac8 100644 --- a/errbot/core_plugins/plugins.py +++ b/errbot/core_plugins/plugins.py @@ -127,15 +127,15 @@ def repos_update(self, _, args): if success: yield f"Update of {d} succeeded...\n\n{feedback}\n\n" - plugin = self._bot.plugin_manager.get_plugin_by_path(d) - if hasattr(plugin, "is_activated") and plugin.is_activated: - name = plugin.name - yield f"/me is reloading plugin {name}" - try: - self._bot.plugin_manager.reload_plugin_by_name(plugin.name) - yield f"Plugin {plugin.name} reloaded." - except PluginActivationException as pae: - yield f"Error reactivating plugin {plugin.name}: {pae}" + for plugin in self._bot.plugin_manager.get_plugins_by_path(d): + if hasattr(plugin, "is_activated") and plugin.is_activated: + name = plugin.name + yield f"/me is reloading plugin {name}" + try: + self._bot.plugin_manager.reload_plugin_by_name(plugin.name) + yield f"Plugin {plugin.name} reloaded." + except PluginActivationException as pae: + yield f"Error reactivating plugin {plugin.name}: {pae}" else: yield f"Update of {d} failed...\n\n{feedback}" diff --git a/errbot/plugin_manager.py b/errbot/plugin_manager.py index f273b9bf5..ecab1718e 100644 --- a/errbot/plugin_manager.py +++ b/errbot/plugin_manager.py @@ -370,6 +370,11 @@ def get_plugin_by_path(self, path): if str(pi.location.parent) == path: return self.plugins[name] + def get_plugins_by_path(self, path): + for name, pi in self.plugin_infos.items(): + if str(pi.location.parent) == path: + yield self.plugins[name] + def deactivate_all_plugins(self): for name in self.get_all_active_plugin_names(): self.deactivate_plugin(name)