diff --git a/deluge/component.py b/deluge/component.py index 9fa4e3c67..4af02264e 100644 --- a/deluge/component.py +++ b/deluge/component.py @@ -99,7 +99,7 @@ class Component(object): _ComponentRegistry.register(self) def __del__(self): - _ComponentRegistry.deregister(self._component_name) + _ComponentRegistry.deregister(self) def _component_start_timer(self): if hasattr(self, "update"): @@ -231,22 +231,22 @@ class ComponentRegistry(object): self.components[obj._component_name] = obj - def deregister(self, name): + def deregister(self, obj): """ Deregisters a component from the registry. A stop will be issued to the component prior to deregistering it. - :param name: the name of the component - :type name: string + :param obj: the Component object + :type obj: object """ - if name in self.components: - log.debug("Deregistering Component: %s", name) - d = self.stop([name]) + if obj in self.components.values(): + log.debug("Deregistering Component: %s", obj._component_name) + d = self.stop([obj._component_name]) def on_stop(result, name): del self.components[name] - return d.addCallback(on_stop, name) + return d.addCallback(on_stop, obj._component_name) else: return succeed(None) diff --git a/deluge/pluginmanagerbase.py b/deluge/pluginmanagerbase.py index e2eb84e90..49e5dada6 100644 --- a/deluge/pluginmanagerbase.py +++ b/deluge/pluginmanagerbase.py @@ -180,7 +180,7 @@ class PluginManagerBase: """Disables a plugin""" try: self.plugins[name].disable() - component.deregister(self.plugins[name].plugin._component_name) + component.deregister(self.plugins[name].plugin) del self.plugins[name] self.config["enabled_plugins"].remove(name) except KeyError: diff --git a/deluge/tests/test_component.py b/deluge/tests/test_component.py index f3a1e174d..ab5e4d534 100644 --- a/deluge/tests/test_component.py +++ b/deluge/tests/test_component.py @@ -94,7 +94,7 @@ class ComponentTestClass(unittest.TestCase): def finish_start_with_depends(self, *args): for c in args[1:]: - component.deregister(c._component_name) + component.deregister(c) def test_start_all(self): def on_start(*args): diff --git a/deluge/tests/test_sessionproxy.py b/deluge/tests/test_sessionproxy.py index bc336c6c1..593fbe075 100644 --- a/deluge/tests/test_sessionproxy.py +++ b/deluge/tests/test_sessionproxy.py @@ -88,7 +88,7 @@ class SessionProxyTestCase(unittest.TestCase): return d def tearDown(self): - return component.deregister("SessionProxy") + return component.deregister(self.sp) def test_startup(self): self.assertEquals(client.core.torrents["a"], self.sp.torrents["a"][1]) diff --git a/deluge/ui/console/modes/torrentdetail.py b/deluge/ui/console/modes/torrentdetail.py index ae9161e1d..a32c1fc02 100644 --- a/deluge/ui/console/modes/torrentdetail.py +++ b/deluge/ui/console/modes/torrentdetail.py @@ -418,7 +418,7 @@ class TorrentDetail(BaseMode, component.Component): def back_to_overview(self): component.stop(["TorrentDetail"]) - component.deregister("TorrentDetail") + component.deregister(self) self.stdscr.clear() component.get("ConsoleUI").set_mode(self.alltorrentmode) self.alltorrentmode.resume()