3715: Plugin manager load/reload does not unload earlier versions of plugins

svn: r14915
This commit is contained in:
Benny Malengier 2010-03-23 13:27:40 +00:00
parent 1f0214abda
commit d83b8d5675

View File

@ -90,6 +90,7 @@ class BasePluginManager(object):
self.__success_list = [] self.__success_list = []
self.__mod2text = {} self.__mod2text = {}
self.__modules = {}
self.__pgr = PluginRegister.get_instance() self.__pgr = PluginRegister.get_instance()
self.__registereddir_set = set() self.__registereddir_set = set()
@ -144,9 +145,17 @@ class BasePluginManager(object):
return self.__loaded_plugins[pdata.id] return self.__loaded_plugins[pdata.id]
need_reload = False need_reload = False
filename = pdata.fname filename = pdata.fname
if filename in self.__modules:
#filename is loaded already, a different plugin in this module
_module = self.__modules[filename]
self.__success_list.append((filename, _module, pdata))
self.__loaded_plugins[pdata.id] = _module
self.__mod2text[_module.__name__] += ' - ' + pdata.description
return _module
if filename in self.__attempt_list: if filename in self.__attempt_list:
#new attempt after a fail, a reload needed #new load attempt after a fail, a reload needed
need_reload = True need_reload = True
#remove previous fail of the plugins in this file
dellist = [] dellist = []
for index, data in enumerate(self.__failmsg_list): for index, data in enumerate(self.__failmsg_list):
if data[0] == filename: if data[0] == filename:
@ -154,7 +163,6 @@ class BasePluginManager(object):
dellist.reverse() dellist.reverse()
for index in dellist: for index in dellist:
del self.__failmsg_list[index] del self.__failmsg_list[index]
else: else:
self.__attempt_list.append(filename) self.__attempt_list.append(filename)
plugin = pdata.mod_name plugin = pdata.mod_name
@ -166,6 +174,7 @@ class BasePluginManager(object):
# Looks like a bug in Python. # Looks like a bug in Python.
reload(_module) reload(_module)
self.__success_list.append((filename, _module, pdata)) self.__success_list.append((filename, _module, pdata))
self.__modules[filename] = _module
self.__loaded_plugins[pdata.id] = _module self.__loaded_plugins[pdata.id] = _module
self.__mod2text[_module.__name__] = pdata.description self.__mod2text[_module.__name__] = pdata.description
return _module return _module
@ -192,18 +201,28 @@ class BasePluginManager(object):
# attempt to reload all plugins that have succeeded in the past # attempt to reload all plugins that have succeeded in the past
self.empty_managed_plugins() self.empty_managed_plugins()
self.__loaded_plugins = {}
oldmodules = self.__modules
self.__modules = {}
dellist = [] dellist = []
#reload first modules that loaded successfully previously
for (index, plugin) in enumerate(self.__success_list): for (index, plugin) in enumerate(self.__success_list):
filename = plugin[0] filename = plugin[0]
pdata = plugin[2] pdata = plugin[2]
filename = filename.replace('pyc','py') filename = filename.replace('pyc','py')
filename = filename.replace('pyo','py') filename = filename.replace('pyo','py')
if filename in self.__modules:
#module already reloaded, a second plugin in same module
continue
try: try:
reload(plugin[1]) reload(plugin[1])
self.__modules[filename] = plugin[1]
self.__loaded_plugins[pdata.id] = plugin[1]
except: except:
dellist.append(index) dellist.append(index)
self.__failmsg_list.append((filename, sys.exc_info(), pdata)) self.__failmsg_list.append((filename, sys.exc_info(), pdata))
dellist.reverse() dellist.reverse()
for index in dellist: for index in dellist:
del self.__success_list[index] del self.__success_list[index]
@ -214,21 +233,7 @@ class BasePluginManager(object):
# attempt to load the plugins that have failed in the past # attempt to load the plugins that have failed in the past
for (filename, message, pdata) in oldfailmsg: for (filename, message, pdata) in oldfailmsg:
name = os.path.split(filename) self.load_plugin(pdata)
match = pymod.match(name[1])
if not match:
continue
self.__attempt_list.append(filename)
plugin = match.groups()[0]
try:
# For some strange reason second importing of a failed plugin
# results in success. Then reload reveals the actual error.
# Looks like a bug in Python.
_module = __import__(plugin)
reload(_module)
self.__success_list.append((filename, _module, pdata))
except:
self.__failmsg_list.append((filename, sys.exc_info(), pdata))
def get_fail_list(self): def get_fail_list(self):
""" Return the list of failed plugins. """ """ Return the list of failed plugins. """