Module: deluge
Branch: master
Commit: 2376e857d284e0fffee97ee2ebc82530a7ecf491

Author: Damien Churchill <[email protected]>
Date:   Fri Apr 23 19:29:29 2010 +0100

fix up the deluge-web plugin interface

---

 deluge/ui/web/js/deluge-all/Plugin.js |    8 ++--
 deluge/ui/web/js/deluge-all/UI.js     |    4 +-
 deluge/ui/web/pluginmanager.py        |   42 ++++++++-------------------
 deluge/ui/web/server.py               |   50 +++++++++++++++++---------------
 4 files changed, 46 insertions(+), 58 deletions(-)

diff --git a/deluge/ui/web/js/deluge-all/Plugin.js 
b/deluge/ui/web/js/deluge-all/Plugin.js
index f4d3195..b22ebbd 100644
--- a/deluge/ui/web/js/deluge-all/Plugin.js
+++ b/deluge/ui/web/js/deluge-all/Plugin.js
@@ -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');
diff --git a/deluge/ui/web/js/deluge-all/UI.js 
b/deluge/ui/web/js/deluge-all/UI.js
index 7ed48cc..48be930 100644
--- a/deluge/ui/web/js/deluge-all/UI.js
+++ b/deluge/ui/web/js/deluge-all/UI.js
@@ -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();
                }
 
diff --git a/deluge/ui/web/pluginmanager.py b/deluge/ui/web/pluginmanager.py
index 4559649..527d98e 100644
--- a/deluge/ui/web/pluginmanager.py
+++ b/deluge/ui/web/pluginmanager.py
@@ -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
\ No newline at end of file
+        return info
diff --git a/deluge/ui/web/server.py b/deluge/ui/web/server.py
index 9690528..cf739a4 100644
--- a/deluge/ui/web/server.py
+++ b/deluge/ui/web/server.py
@@ -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)
 
@@ -488,18 +504,6 @@ class TopLevel(resource.Resource):
         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
 

-- 
You received this message because you are subscribed to the Google Groups 
"deluge-commit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/deluge-commit?hl=en.

Reply via email to