From 8271d70ec7adc1bac5158bad875283d4ac063323 Mon Sep 17 00:00:00 2001 From: Andrew Resch Date: Tue, 11 Dec 2007 04:45:47 +0000 Subject: [PATCH] Plugin system changes in regards to enabling/disabling plugins. --- deluge/core/pluginmanager.py | 28 +++++++++++++++++++++- deluge/pluginmanagerbase.py | 13 ++++++---- deluge/plugins/corepluginbase.py | 1 + deluge/plugins/queue/queue/core.py | 3 +++ deluge/plugins/queue/queue/torrentqueue.py | 3 ++- deluge/ui/gtkui/pluginmanager.py | 12 +++++++--- 6 files changed, 50 insertions(+), 10 deletions(-) diff --git a/deluge/core/pluginmanager.py b/deluge/core/pluginmanager.py index 067f63056..eb69f4e18 100644 --- a/deluge/core/pluginmanager.py +++ b/deluge/core/pluginmanager.py @@ -33,6 +33,8 @@ """PluginManager for Core""" +import gobject + import deluge.pluginmanagerbase import deluge.component as component from deluge.log import LOG as log @@ -52,11 +54,35 @@ class PluginManager(deluge.pluginmanagerbase.PluginManagerBase, } self.status_fields = {} - + # Call the PluginManagerBase constructor deluge.pluginmanagerbase.PluginManagerBase.__init__( self, "core.conf", "deluge.plugin.core") + def start(self): + # Enable plugins that are enabled in the config + self.enable_plugins() + + # Set update timer to call update() in plugins every second + self.update_timer = gobject.timeout_add(1000, self.update_plugins) + + def stop(self): + # Disable all enabled plugins + self.disable_plugins() + # Stop the update timer + gobject.source_remove(self.update_timer) + + def shutdown(self): + self.stop() + + def update_plugins(self): + for plugin in self.plugins.keys(): + try: + self.plugins[plugin].update() + except AttributeError: + # We don't care if this doesn't work + pass + def get_core(self): """Returns a reference to the core""" return self.core diff --git a/deluge/pluginmanagerbase.py b/deluge/pluginmanagerbase.py index a66d9543b..774001a2c 100644 --- a/deluge/pluginmanagerbase.py +++ b/deluge/pluginmanagerbase.py @@ -58,14 +58,15 @@ class PluginManagerBase: # Scan the plugin folders for plugins self.scan_for_plugins() + def enable_plugins(self): # Load plugins that are enabled in the config. for name in self.config["enabled_plugins"]: self.enable_plugin(name) - - def shutdown(self): - for plugin in self.plugins.values(): - plugin.disable() - del self.plugins + + def disable_plugins(self): + # Disable all plugins that are enabled + for key in self.plugins.keys(): + self.plugins[key].disable() def __getitem__(self, key): return self.plugins[key] @@ -111,6 +112,8 @@ class PluginManagerBase: plugin_name = plugin_name.replace("-", " ") self.plugins[plugin_name] = instance if plugin_name not in self.config["enabled_plugins"]: + log.debug("Adding %s to enabled_plugins list in config", + plugin_name) self.config["enabled_plugins"].append(plugin_name) log.info("Plugin %s enabled..", plugin_name) diff --git a/deluge/plugins/corepluginbase.py b/deluge/plugins/corepluginbase.py index 188dc5053..e6f393a17 100644 --- a/deluge/plugins/corepluginbase.py +++ b/deluge/plugins/corepluginbase.py @@ -45,3 +45,4 @@ class CorePluginBase: getattr(self, "%s" % func), plugin_name.lower()\ + "_" + func[7:]) log.debug("CorePlugin initialized..") + diff --git a/deluge/plugins/queue/queue/core.py b/deluge/plugins/queue/queue/core.py index 992ee7454..c8ea98659 100644 --- a/deluge/plugins/queue/queue/core.py +++ b/deluge/plugins/queue/queue/core.py @@ -66,6 +66,9 @@ class Core(CorePluginBase): # De-register status fields self.plugin.deregister_status_field("queue") + def update(self): + pass + ## Hooks for core ## def _post_torrent_add(self, torrent_id): if torrent_id is not None: diff --git a/deluge/plugins/queue/queue/torrentqueue.py b/deluge/plugins/queue/queue/torrentqueue.py index a07df8a91..87ddd6281 100644 --- a/deluge/plugins/queue/queue/torrentqueue.py +++ b/deluge/plugins/queue/queue/torrentqueue.py @@ -40,6 +40,7 @@ class TorrentQueue: def __init__(self, torrent_list): # Try to load the queue state from file self.queue = self.load_state() + # First remove any torrent_ids in self.queue that are not in the current # session list. for torrent_id in self.queue: @@ -50,7 +51,7 @@ class TorrentQueue: for torrent_id in torrent_list: if torrent_id not in self.queue: self.queue.append(torrent_id) - + def __getitem__(self, torrent_id): """Return the queue position of the torrent_id""" try: diff --git a/deluge/ui/gtkui/pluginmanager.py b/deluge/ui/gtkui/pluginmanager.py index 41bf263b0..8a545faaf 100644 --- a/deluge/ui/gtkui/pluginmanager.py +++ b/deluge/ui/gtkui/pluginmanager.py @@ -42,7 +42,9 @@ class PluginManager(deluge.pluginmanagerbase.PluginManagerBase, def __init__(self): component.Component.__init__(self, "PluginManager") self.config = ConfigManager("gtkui.conf") - + deluge.pluginmanagerbase.PluginManagerBase.__init__( + self, "gtkui.conf", "deluge.plugin.gtkui") + def start(self): """Start the plugin manager""" # Update the enabled_plugins from the core @@ -51,9 +53,13 @@ class PluginManager(deluge.pluginmanagerbase.PluginManagerBase, enabled_plugins = list(set(enabled_plugins)) self.config["enabled_plugins"] = enabled_plugins - deluge.pluginmanagerbase.PluginManagerBase.__init__( - self, "gtkui.conf", "deluge.plugin.gtkui") + # Enable the plugins that are enabled in the config and core + self.enable_plugins() + def stop(self): + # Disable the plugins + self.disable_plugins() + ## Plugin functions.. will likely move to own class.. def add_torrentview_text_column(self, *args, **kwargs):