From d70abd2986585e0c9a20fe1ee5558ea2a06f82be Mon Sep 17 00:00:00 2001 From: Calum Lind Date: Wed, 31 Oct 2018 09:53:22 +0000 Subject: [PATCH] [Plugins] Refactor plugin scan code Simplify adding entries to the working_set. Also fixes adding files rather than just dirs to working_set. --- deluge/pluginmanagerbase.py | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/deluge/pluginmanagerbase.py b/deluge/pluginmanagerbase.py index b6335d2d9..f838cd3cb 100644 --- a/deluge/pluginmanagerbase.py +++ b/deluge/pluginmanagerbase.py @@ -94,19 +94,18 @@ class PluginManagerBase(object): def scan_for_plugins(self): """Scans for available plugins""" - base_plugin_dir = deluge.common.resource_filename('deluge', 'plugins') - pkg_resources.working_set.add_entry(base_plugin_dir) - user_plugin_dir = os.path.join(deluge.configmanager.get_config_dir(), 'plugins') + base_dir = deluge.common.resource_filename('deluge', 'plugins') + user_dir = os.path.join(deluge.configmanager.get_config_dir(), 'plugins') + base_subdir = [ + os.path.join(base_dir, f) + for f in os.listdir(base_dir) + if os.path.isdir(os.path.join(base_dir, f)) + ] + plugin_dirs = [base_dir, user_dir] + base_subdir - plugins_dirs = [base_plugin_dir] - for dirname in os.listdir(base_plugin_dir): - plugin_dir = os.path.join(base_plugin_dir, dirname) - pkg_resources.working_set.add_entry(plugin_dir) - plugins_dirs.append(plugin_dir) - pkg_resources.working_set.add_entry(user_plugin_dir) - plugins_dirs.append(user_plugin_dir) - - self.pkg_env = pkg_resources.Environment(plugins_dirs, None) + for dirname in plugin_dirs: + pkg_resources.working_set.add_entry(dirname) + self.pkg_env = pkg_resources.Environment(plugin_dirs, None) self.available_plugins = [] for name in self.pkg_env: @@ -139,13 +138,13 @@ class PluginManagerBase(object): plugin_name = plugin_name.replace(' ', '-') egg = self.pkg_env[plugin_name][0] + # Activate is required by non-namespace plugins. egg.activate() return_d = defer.succeed(True) for name in egg.get_entry_map(self.entry_name): - entry_point = egg.get_entry_info(self.entry_name, name) try: - cls = entry_point.load() + cls = egg.load_entry_point(self.entry_name, name) instance = cls(plugin_name.replace('-', '_')) except component.ComponentAlreadyRegistered as ex: log.error(ex)