Author: andar

Revision: 5924

Log:
        Fix disabling/enabling plugins after switching daemons

Diff:
Modified: branches/1.2_RC/ChangeLog
===================================================================
--- branches/1.2_RC/ChangeLog   2009-11-06 19:22:13 UTC (rev 5923)
+++ branches/1.2_RC/ChangeLog   2009-11-08 04:04:40 UTC (rev 5924)
@@ -5,6 +5,7 @@
 ==== GtkUI ====
        * Fix showing the 'Other' speed dialogs in Windows
        * Fix adding torrents from the Queued Torrents dialog
+       * Fix disabling/enabling plugins after switching daemons
 
 ==== Web ====
        * Fix installing the deluge-web manpage

Modified: branches/1.2_RC/deluge/component.py
===================================================================
--- branches/1.2_RC/deluge/component.py 2009-11-06 19:22:13 UTC (rev 5923)
+++ branches/1.2_RC/deluge/component.py 2009-11-08 04:04:40 UTC (rev 5924)
@@ -101,6 +101,13 @@
         if depend != None:
             self.depend[name] = depend
 
+    def deregister(self, name):
+        """Deregisters a component"""
+        if name in self.components:
+            log.debug("Deregistering Component: %s", name)
+            self.stop_component(name)
+            del self.components[name]
+
     def get(self, name):
         """Returns a reference to the component 'name'"""
         return self.components[name]
@@ -126,8 +133,14 @@
 
     def stop(self):
         """Stops all components"""
-        for component in self.components.keys():
-            self.stop_component(component)
+        # We create a separate list of the keys and do an additional check to
+        # make sure the key still exists in the components dict.
+        # This is because components could be deregistered during a stop and
+        # the dictionary would get modified while iterating through it.
+        components = self.components.keys()
+        for component in components:
+            if component in self.components:
+                self.stop_component(component)
 
     def stop_component(self, component):
         if self.components[component].get_state() != \
@@ -187,6 +200,10 @@
     """Registers a component with the registry"""
     _ComponentRegistry.register(name, obj, depend)
 
+def deregister(name):
+    """Deregisters a component"""
+    _ComponentRegistry.deregister(name)
+
 def start(component=None):
     """Starts all components"""
     if component == None:

Modified: branches/1.2_RC/deluge/pluginmanagerbase.py
===================================================================
--- branches/1.2_RC/deluge/pluginmanagerbase.py 2009-11-06 19:22:13 UTC (rev 
5923)
+++ branches/1.2_RC/deluge/pluginmanagerbase.py 2009-11-08 04:04:40 UTC (rev 
5924)
@@ -87,7 +87,7 @@
     def disable_plugins(self):
         # Disable all plugins that are enabled
         for key in self.plugins.keys():
-            self.plugins[key].disable()
+            self.disable_plugin(key)
 
     def __getitem__(self, key):
         return self.plugins[key]
@@ -153,6 +153,7 @@
         """Disables a plugin"""
         try:
             self.plugins[name].disable()
+            
component.deregister(self.plugins[name].plugin.get_component_name())
             del self.plugins[name]
             self.config["enabled_plugins"].remove(name)
         except KeyError:

Modified: trunk/deluge/component.py
===================================================================
--- trunk/deluge/component.py   2009-11-06 19:22:13 UTC (rev 5923)
+++ trunk/deluge/component.py   2009-11-08 04:04:40 UTC (rev 5924)
@@ -101,6 +101,13 @@
         if depend != None:
             self.depend[name] = depend
 
+    def deregister(self, name):
+        """Deregisters a component"""
+        if name in self.components:
+            log.debug("Deregistering Component: %s", name)
+            self.stop_component(name)
+            del self.components[name]
+
     def get(self, name):
         """Returns a reference to the component 'name'"""
         return self.components[name]
@@ -126,8 +133,14 @@
 
     def stop(self):
         """Stops all components"""
-        for component in self.components.keys():
-            self.stop_component(component)
+        # We create a separate list of the keys and do an additional check to
+        # make sure the key still exists in the components dict.
+        # This is because components could be deregistered during a stop and
+        # the dictionary would get modified while iterating through it.
+        components = self.components.keys()
+        for component in components:
+            if component in self.components:
+                self.stop_component(component)
 
     def stop_component(self, component):
         if self.components[component].get_state() != \
@@ -187,6 +200,10 @@
     """Registers a component with the registry"""
     _ComponentRegistry.register(name, obj, depend)
 
+def deregister(name):
+    """Deregisters a component"""
+    _ComponentRegistry.deregister(name)
+
 def start(component=None):
     """Starts all components"""
     if component == None:

Modified: trunk/deluge/pluginmanagerbase.py
===================================================================
--- trunk/deluge/pluginmanagerbase.py   2009-11-06 19:22:13 UTC (rev 5923)
+++ trunk/deluge/pluginmanagerbase.py   2009-11-08 04:04:40 UTC (rev 5924)
@@ -87,7 +87,7 @@
     def disable_plugins(self):
         # Disable all plugins that are enabled
         for key in self.plugins.keys():
-            self.plugins[key].disable()
+            self.disable_plugin(key)
 
     def __getitem__(self, key):
         return self.plugins[key]
@@ -153,6 +153,7 @@
         """Disables a plugin"""
         try:
             self.plugins[name].disable()
+            
component.deregister(self.plugins[name].plugin.get_component_name())
             del self.plugins[name]
             self.config["enabled_plugins"].remove(name)
         except KeyError:



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