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

svn: r14861
This commit is contained in:
Benny Malengier 2010-03-18 22:27:45 +00:00
parent 38ae88a4ee
commit 306671f9af
2 changed files with 28 additions and 4 deletions

View File

@ -799,8 +799,8 @@ Location: %(fpath)s
model, node = selection.get_selected()
if not node:
return
id = model.get_value(node, id_col)
pdata = self.__preg.get_plugin(id)
idv = model.get_value(node, id_col)
pdata = self.__preg.get_plugin(idv)
self.__pmgr.load_plugin(pdata)
self.__rebuild_load_list()

View File

@ -142,17 +142,36 @@ class BasePluginManager(object):
"""
if pdata.id in self.__loaded_plugins:
return self.__loaded_plugins[pdata.id]
reload = False
filename = pdata.fname
self.__attempt_list.append(filename)
if filename in self.__attempt_list:
#new attempt after a fail, a reload needed
reload = True
dellist = []
for index, data in enumerate(self.__failmsg_list):
if data[0] == filename:
dellist.append(index)
dellist.reverse()
for index in dellist:
del self.__failmsg_list[index]
else:
self.__attempt_list.append(filename)
plugin = pdata.mod_name
try:
_module = __import__(plugin)
if reload:
# 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.
reload(_module)
self.__success_list.append((filename, _module, pdata))
self.__loaded_plugins[pdata.id] = _module
self.__mod2text[_module.__name__] = pdata.description
return _module
except:
self.__failmsg_list.append((filename, sys.exc_info(), pdata))
return None
def empty_managed_plugins(self):
@ -174,7 +193,8 @@ class BasePluginManager(object):
# attempt to reload all plugins that have succeeded in the past
self.empty_managed_plugins()
for plugin in self.__success_list:
dellist = []
for (index, plugin) in enumerate(self.__success_list):
filename = plugin[0]
pdata = plugin[2]
filename = filename.replace('pyc','py')
@ -182,7 +202,11 @@ class BasePluginManager(object):
try:
reload(plugin[1])
except:
dellist.append(index)
self.__failmsg_list.append((filename, sys.exc_info(), pdata))
dellist.reverse()
for index in dellist:
del self.__success_list[index]
# Remove previously good plugins that are now bad
# from the registered lists