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"""
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

View File

@ -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)

View File

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

View File

@ -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:

View File

@ -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:

View File

@ -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):