Plugin system changes in regards to enabling/disabling plugins.

This commit is contained in:
Andrew Resch 2007-12-11 04:45:47 +00:00
parent f3cdfa8351
commit 8271d70ec7
6 changed files with 50 additions and 10 deletions

View File

@ -33,6 +33,8 @@
"""PluginManager for Core""" """PluginManager for Core"""
import gobject
import deluge.pluginmanagerbase import deluge.pluginmanagerbase
import deluge.component as component import deluge.component as component
from deluge.log import LOG as log from deluge.log import LOG as log
@ -57,6 +59,30 @@ class PluginManager(deluge.pluginmanagerbase.PluginManagerBase,
deluge.pluginmanagerbase.PluginManagerBase.__init__( deluge.pluginmanagerbase.PluginManagerBase.__init__(
self, "core.conf", "deluge.plugin.core") 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): def get_core(self):
"""Returns a reference to the core""" """Returns a reference to the core"""
return self.core return self.core

View File

@ -58,14 +58,15 @@ class PluginManagerBase:
# Scan the plugin folders for plugins # Scan the plugin folders for plugins
self.scan_for_plugins() self.scan_for_plugins()
def enable_plugins(self):
# Load plugins that are enabled in the config. # Load plugins that are enabled in the config.
for name in self.config["enabled_plugins"]: for name in self.config["enabled_plugins"]:
self.enable_plugin(name) self.enable_plugin(name)
def shutdown(self): def disable_plugins(self):
for plugin in self.plugins.values(): # Disable all plugins that are enabled
plugin.disable() for key in self.plugins.keys():
del self.plugins self.plugins[key].disable()
def __getitem__(self, key): def __getitem__(self, key):
return self.plugins[key] return self.plugins[key]
@ -111,6 +112,8 @@ class PluginManagerBase:
plugin_name = plugin_name.replace("-", " ") plugin_name = plugin_name.replace("-", " ")
self.plugins[plugin_name] = instance self.plugins[plugin_name] = instance
if plugin_name not in self.config["enabled_plugins"]: 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) self.config["enabled_plugins"].append(plugin_name)
log.info("Plugin %s enabled..", plugin_name) log.info("Plugin %s enabled..", plugin_name)

View File

@ -45,3 +45,4 @@ class CorePluginBase:
getattr(self, "%s" % func), plugin_name.lower()\ getattr(self, "%s" % func), plugin_name.lower()\
+ "_" + func[7:]) + "_" + func[7:])
log.debug("CorePlugin initialized..") log.debug("CorePlugin initialized..")

View File

@ -66,6 +66,9 @@ class Core(CorePluginBase):
# De-register status fields # De-register status fields
self.plugin.deregister_status_field("queue") self.plugin.deregister_status_field("queue")
def update(self):
pass
## Hooks for core ## ## Hooks for core ##
def _post_torrent_add(self, torrent_id): def _post_torrent_add(self, torrent_id):
if torrent_id is not None: if torrent_id is not None:

View File

@ -40,6 +40,7 @@ class TorrentQueue:
def __init__(self, torrent_list): def __init__(self, torrent_list):
# Try to load the queue state from file # Try to load the queue state from file
self.queue = self.load_state() self.queue = self.load_state()
# First remove any torrent_ids in self.queue that are not in the current # First remove any torrent_ids in self.queue that are not in the current
# session list. # session list.
for torrent_id in self.queue: for torrent_id in self.queue:

View File

@ -42,6 +42,8 @@ class PluginManager(deluge.pluginmanagerbase.PluginManagerBase,
def __init__(self): def __init__(self):
component.Component.__init__(self, "PluginManager") component.Component.__init__(self, "PluginManager")
self.config = ConfigManager("gtkui.conf") self.config = ConfigManager("gtkui.conf")
deluge.pluginmanagerbase.PluginManagerBase.__init__(
self, "gtkui.conf", "deluge.plugin.gtkui")
def start(self): def start(self):
"""Start the plugin manager""" """Start the plugin manager"""
@ -51,8 +53,12 @@ class PluginManager(deluge.pluginmanagerbase.PluginManagerBase,
enabled_plugins = list(set(enabled_plugins)) enabled_plugins = list(set(enabled_plugins))
self.config["enabled_plugins"] = enabled_plugins self.config["enabled_plugins"] = enabled_plugins
deluge.pluginmanagerbase.PluginManagerBase.__init__( # Enable the plugins that are enabled in the config and core
self, "gtkui.conf", "deluge.plugin.gtkui") self.enable_plugins()
def stop(self):
# Disable the plugins
self.disable_plugins()
## Plugin functions.. will likely move to own class.. ## Plugin functions.. will likely move to own class..