From 306671f9af5e720a3337441295cf8a9dc2fa4fb5 Mon Sep 17 00:00:00 2001 From: Benny Malengier Date: Thu, 18 Mar 2010 22:27:45 +0000 Subject: [PATCH] 3715: Plugin manager load/reload does not unload earlier versions of plugins svn: r14861 --- src/PluginUtils/_PluginWindows.py | 4 ++-- src/gen/plug/_manager.py | 28 ++++++++++++++++++++++++++-- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/PluginUtils/_PluginWindows.py b/src/PluginUtils/_PluginWindows.py index c9338ebea..ec8e1d6b1 100644 --- a/src/PluginUtils/_PluginWindows.py +++ b/src/PluginUtils/_PluginWindows.py @@ -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() diff --git a/src/gen/plug/_manager.py b/src/gen/plug/_manager.py index 3ebc83c81..4ef075e96 100644 --- a/src/gen/plug/_manager.py +++ b/src/gen/plug/_manager.py @@ -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