fix up the deluge-web plugin interface

This commit is contained in:
Damien Churchill 2010-04-23 19:29:29 +01:00
parent d024c293ed
commit 2376e857d2
4 changed files with 46 additions and 58 deletions

View File

@ -29,6 +29,7 @@
* this exception statement from your version. If you delete this exception
* statement from all source files in the program, then also delete it here.
*/
Ext.ns('Deluge');
/**
* @class Deluge.Plugin
@ -44,9 +45,8 @@ Deluge.Plugin = Ext.extend(Ext.util.Observable, {
name: null,
constructor: function(config) {
this.name = config.name;
this.isDelugePlugin = true;
this.addEvents({
/**
* @event enabled
* @param {Plugin} plugin the plugin instance
@ -59,8 +59,6 @@ Deluge.Plugin = Ext.extend(Ext.util.Observable, {
*/
"disabled": true
});
this.isDelugePlugin = true;
Deluge.Plugins[this.name] = this;
Deluge.Plugin.superclass.constructor.call(this, config);
},
@ -82,3 +80,5 @@ Deluge.Plugin = Ext.extend(Ext.util.Observable, {
if (this.onEnable) this.onEnable();
}
});
Ext.ns('Deluge.plugins');

View File

@ -79,8 +79,8 @@ deluge.ui = {
url: deluge.config.base + 'json'
});
for (var plugin in deluge.dlugins) {
plugin = deluge.plugins[plugin];
for (var plugin in Deluge.plugins) {
plugin = new Deluge.plugins[plugin]();
plugin.enable();
}

View File

@ -87,23 +87,14 @@ class PluginManager(PluginManagerBase, component.Component):
return
info = gather_info(plugin)
server = component.get("DelugeWeb").top_level
js = component.get("Javascript")
for directory in info["script_directories"]:
js.removeDirectory(directory, name.lower())
scripts = component.get("Scripts")
for script in info["scripts"]:
script = "/js/%s/%s" % (name.lower(), os.path.basename(script))
if script not in server.scripts:
continue
server.scripts.remove(script)
scripts.remove_script("%s/%s" % (name.lower(), os.path.basename(script).lower()))
for script in info["debug_scripts"]:
script = "/js/%s/%s" % (name.lower(), os.path.basename(script))
if script not in server.debug_scripts:
continue
server.debug_scripts.remove(script)
scripts.remove_script("%s/%s" % (name.lower(), os.path.basename(script).lower()))
scripts.remove_script("%s/%s" % (name.lower(), os.path.basename(script).lower()))
super(PluginManager, self).disable_plugin(name)
@ -119,22 +110,15 @@ class PluginManager(PluginManagerBase, component.Component):
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())
scripts = component.get("Scripts")
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)
log.debug("adding script %s for %s", name, os.path.basename(script))
scripts.add_script("%s/%s" % (name.lower(), os.path.basename(script)), 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)
log.debug("adding debug script %s for %s", name, os.path.basename(script))
scripts.add_script("%s/%s" % (name.lower(), os.path.basename(script)), script, "debug")
scripts.add_script("%s/%s" % (name.lower(), os.path.basename(script)), script, "dev")
def start(self):
"""
@ -165,4 +149,4 @@ class PluginManager(PluginManagerBase, component.Component):
info["scripts"] = ["/js/%s/%s" % (name.lower(), os.path.basename(s)) for s in info["scripts"]]
info["debug_scripts"] = ["/js/%s/%s" % (name.lower(), os.path.basename(s)) for s in info["debug_scripts"]]
del info["script_directories"]
return info
return info

View File

@ -336,7 +336,7 @@ class ScriptResource(resource.Resource, component.Component):
"""
Adds a folder of scripts to the script resource.
:param path: The path of the script (this supports globbing)
:param path: The path of the folder
:type path: string
:param filepath: The physical location of the script
:type filepath: string
@ -351,6 +351,22 @@ class ScriptResource(resource.Resource, component.Component):
self.__scripts[type]["scripts"][path] = (filepath, recurse)
self.__scripts[type]["order"].append(path)
def remove_script(self, path, type=None):
"""
Removes a script or folder of scripts from the script resource.
:param path: The path of the folder
:type path: string
:keyword type: The type of script to add (normal, debug, dev)
:param type: string
"""
if type not in ("dev", "debug", "normal"):
type = "normal"
del self.__scripts[type]["scripts"][path]
self.__scripts[type]["order"].remove(path)
def get_scripts(self, type=None):
"""
Returns a list of the scripts that can be used for producing
@ -457,22 +473,22 @@ class TopLevel(resource.Resource):
js = ScriptResource()
# configure the dev scripts
js.add_script("ext-base.js", rpath("js", "ext-base-debug.js"), "dev")
js.add_script("ext-all.js", rpath("js", "ext-all-debug.js"), "dev")
js.add_script("ext-base-debug.js", rpath("js", "ext-base-debug.js"), "dev")
js.add_script("ext-all-debug.js", rpath("js", "ext-all-debug.js"), "dev")
js.add_script_folder("ext-extensions", rpath("js", "ext-extensions"), "dev")
js.add_script_folder("deluge-all", rpath("js", "deluge-all"), "dev")
# configure the debug scripts
js.add_script("ext-base.js", rpath("js", "ext-base-debug.js"), "debug")
js.add_script("ext-all.js", rpath("js", "ext-all-debug.js"), "debug")
js.add_script("ext-extensions.js", rpath("js", "ext-extensions-debug.js"), "debug")
js.add_script("deluge-all.js", rpath("js", "deluge-all-debug.js"), "debug")
js.add_script("ext-base-debug.js", rpath("js", "ext-base-debug.js"), "debug")
js.add_script("ext-all-debug.js", rpath("js", "ext-all-debug.js"), "debug")
js.add_script("ext-extensions-debug.js", rpath("js", "ext-extensions-debug.js"), "debug")
js.add_script("deluge-all-debug.js", rpath("js", "deluge-all-debug.js"), "debug")
# configure the normal scripts
js.add_script("ext-base.js", rpath("js", "ext-base.js"), "debug")
js.add_script("ext-all.js", rpath("js", "ext-all.js"), "debug")
js.add_script("ext-extensions.js", rpath("js", "ext-extensions.js"), "debug")
js.add_script("deluge-all.js", rpath("js", "deluge-all.js"), "debug")
js.add_script("ext-base.js", rpath("js", "ext-base.js"))
js.add_script("ext-all.js", rpath("js", "ext-all.js"))
js.add_script("ext-extensions.js", rpath("js", "ext-extensions.js"))
js.add_script("deluge-all.js", rpath("js", "deluge-all.js"))
self.putChild("js", js)
@ -487,18 +503,6 @@ class TopLevel(resource.Resource):
theme = CONFIG_DEFAULTS.get("theme")
self.__stylesheets.insert(1, "themes/css/xtheme-%s.css" % theme)
@property
def scripts(self):
return self.__scripts
@property
def debug_scripts(self):
return self.__debug_scripts
@property
def dev_scripts(self):
return self.__dev_scripts
@property
def stylesheets(self):
return self.__stylesheets