mirror of
https://git.deluge-torrent.org/deluge
synced 2025-09-16 23:11:54 +00:00
improve the plugin manager so that it handles the adding and removing of scripts
This commit is contained in:
parent
b164fef0c5
commit
fc1b1a6aa8
1 changed files with 72 additions and 5 deletions
|
@ -33,29 +33,96 @@
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
|
|
||||||
|
import os
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from deluge.component import Component
|
from deluge import component
|
||||||
from deluge.pluginmanagerbase import PluginManagerBase
|
from deluge.pluginmanagerbase import PluginManagerBase
|
||||||
from deluge.ui.client import client
|
from deluge.ui.client import client
|
||||||
from deluge.configmanager import ConfigManager
|
from deluge.configmanager import ConfigManager
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
class PluginManager(PluginManagerBase, Component):
|
def gather_info(plugin):
|
||||||
|
# Get the scripts for the plugin
|
||||||
|
scripts = getattr(plugin, "scripts", ())
|
||||||
|
debug_scripts = getattr(plugin, "debug_scripts") or scripts
|
||||||
|
|
||||||
|
directories = []
|
||||||
|
for script in scripts + debug_scripts:
|
||||||
|
if os.path.dirname(script) not in directories:
|
||||||
|
directories.append(os.path.dirname(script))
|
||||||
|
|
||||||
|
return {
|
||||||
|
"scripts": scripts,
|
||||||
|
"debug_scripts": debug_scripts,
|
||||||
|
"script_directories": directories
|
||||||
|
}
|
||||||
|
|
||||||
|
class PluginManager(PluginManagerBase, component.Component):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
Component.__init__(self, "Web.PluginManager")
|
component.Component.__init__(self, "Web.PluginManager")
|
||||||
self.config = ConfigManager("web.conf")
|
self.config = ConfigManager("web.conf")
|
||||||
PluginManagerBase.__init__(self, "web.conf", "deluge.plugin.web")
|
PluginManagerBase.__init__(self, "web.conf", "deluge.plugin.web")
|
||||||
|
|
||||||
|
client.register_event_handler("PluginEnabledEvent", self._on_plugin_enabled_event)
|
||||||
|
client.register_event_handler("PluginDisabledEvent", self._on_plugin_disabled_event)
|
||||||
|
|
||||||
def _on_get_enabled_plugins(self, plugins):
|
def _on_get_enabled_plugins(self, plugins):
|
||||||
pass
|
for plugin in plugins:
|
||||||
|
self.enable_plugin(plugin)
|
||||||
|
|
||||||
|
def _on_plugin_enabled_event(self, name):
|
||||||
|
self.enable_plugin(name)
|
||||||
|
|
||||||
|
def _on_plugin_disabled_event(self, name):
|
||||||
|
self.disable_plugin(name)
|
||||||
|
|
||||||
|
def disable_plugin(self, name):
|
||||||
|
# Get the plugin instance
|
||||||
|
try:
|
||||||
|
plugin = component.get("WebPlugin." + name)
|
||||||
|
except KeyError:
|
||||||
|
log.info("Plugin has no web ui")
|
||||||
|
return
|
||||||
|
|
||||||
|
server = component.get("DelugeWeb").top_level
|
||||||
|
|
||||||
|
super(PluginManager, self).disable_plugin(name)
|
||||||
|
|
||||||
|
def enable_plugin(self, name):
|
||||||
|
super(PluginManager, self).enable_plugin(name)
|
||||||
|
|
||||||
|
# Get the plugin instance
|
||||||
|
try:
|
||||||
|
plugin = component.get("WebPlugin." + name)
|
||||||
|
except KeyError:
|
||||||
|
log.info("Plugin has no web ui")
|
||||||
|
return
|
||||||
|
|
||||||
|
info = gather_info(plugin)
|
||||||
|
|
||||||
|
server = component.get("DelugeWeb").top_level
|
||||||
|
js = component.get("Javascript")
|
||||||
|
for directory in info["script_directories"]:
|
||||||
|
js.addDirectory(directory, name.lower())
|
||||||
|
|
||||||
|
for script in info["scripts"]:
|
||||||
|
script = "/js/%s/%s" % (name.lower(), os.path.basename(script))
|
||||||
|
if script in server.scripts:
|
||||||
|
continue
|
||||||
|
server.scripts.append(script)
|
||||||
|
|
||||||
|
for script in info["debug_scripts"]:
|
||||||
|
script = "/js/%s/%s" % (name.lower(), os.path.basename(script))
|
||||||
|
if script in server.debug_scripts:
|
||||||
|
continue
|
||||||
|
server.debug_scripts.append(script)
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
"""
|
"""
|
||||||
Start up the plugin manager
|
Start up the plugin manager
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# Update the enabled plugins from the core
|
# Update the enabled plugins from the core
|
||||||
d = client.core.get_enabled_plugins()
|
d = client.core.get_enabled_plugins()
|
||||||
d.addCallback(self._on_get_enabled_plugins)
|
d.addCallback(self._on_get_enabled_plugins)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue