Skip to content

Commit

Permalink
Reload all plugins in a repo
Browse files Browse the repository at this point in the history
`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.
  • Loading branch information
bboe committed Jul 10, 2021
1 parent d5ce6ce commit bb0e00b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
18 changes: 9 additions & 9 deletions errbot/core_plugins/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}"

Expand Down
5 changes: 5 additions & 0 deletions errbot/plugin_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit bb0e00b

Please sign in to comment.