Fix disabling/enabling plugins after switching daemons

This commit is contained in:
Andrew Resch 2009-11-08 04:04:40 +00:00
parent dd67a935cb
commit 9b8282010c
2 changed files with 21 additions and 3 deletions

View File

@ -101,6 +101,13 @@ class ComponentRegistry:
if depend != None: if depend != None:
self.depend[name] = depend 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): def get(self, name):
"""Returns a reference to the component 'name'""" """Returns a reference to the component 'name'"""
return self.components[name] return self.components[name]
@ -126,8 +133,14 @@ class ComponentRegistry:
def stop(self): def stop(self):
"""Stops all components""" """Stops all components"""
for component in self.components.keys(): # We create a separate list of the keys and do an additional check to
self.stop_component(component) # 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): def stop_component(self, component):
if self.components[component].get_state() != \ if self.components[component].get_state() != \
@ -187,6 +200,10 @@ def register(name, obj, depend=None):
"""Registers a component with the registry""" """Registers a component with the registry"""
_ComponentRegistry.register(name, obj, depend) _ComponentRegistry.register(name, obj, depend)
def deregister(name):
"""Deregisters a component"""
_ComponentRegistry.deregister(name)
def start(component=None): def start(component=None):
"""Starts all components""" """Starts all components"""
if component == None: if component == None:

View File

@ -87,7 +87,7 @@ class PluginManagerBase:
def disable_plugins(self): def disable_plugins(self):
# Disable all plugins that are enabled # Disable all plugins that are enabled
for key in self.plugins.keys(): for key in self.plugins.keys():
self.plugins[key].disable() self.disable_plugin(key)
def __getitem__(self, key): def __getitem__(self, key):
return self.plugins[key] return self.plugins[key]
@ -153,6 +153,7 @@ class PluginManagerBase:
"""Disables a plugin""" """Disables a plugin"""
try: try:
self.plugins[name].disable() self.plugins[name].disable()
component.deregister(self.plugins[name].plugin.get_component_name())
del self.plugins[name] del self.plugins[name]
self.config["enabled_plugins"].remove(name) self.config["enabled_plugins"].remove(name)
except KeyError: except KeyError: