Plugin system changes in regards to enabling/disabling plugins.
This commit is contained in:
parent
f3cdfa8351
commit
8271d70ec7
|
@ -33,6 +33,8 @@
|
|||
|
||||
"""PluginManager for Core"""
|
||||
|
||||
import gobject
|
||||
|
||||
import deluge.pluginmanagerbase
|
||||
import deluge.component as component
|
||||
from deluge.log import LOG as log
|
||||
|
@ -57,6 +59,30 @@ class PluginManager(deluge.pluginmanagerbase.PluginManagerBase,
|
|||
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
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -45,3 +45,4 @@ class CorePluginBase:
|
|||
getattr(self, "%s" % func), plugin_name.lower()\
|
||||
+ "_" + func[7:])
|
||||
log.debug("CorePlugin initialized..")
|
||||
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -42,6 +42,8 @@ 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"""
|
||||
|
@ -51,8 +53,12 @@ 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..
|
||||
|
||||
|
|
Loading…
Reference in New Issue