Fix #2151 (cannot reload the OTR plugin)

We were using the deprecated imp methods, now we use importlib
This commit is contained in:
mathieui 2012-11-17 23:03:38 +01:00
parent ac806cbb41
commit a1c3d0dcdf

View file

@ -5,7 +5,7 @@ the API together. Defines also a bunch of variables related to the
plugin env. plugin env.
""" """
import imp import importlib
import os import os
import sys import sys
import logging import logging
@ -39,6 +39,7 @@ except OSError:
pass pass
sys.path.append(plugins_dir) sys.path.append(plugins_dir)
finder = importlib.machinery.PathFinder()
class PluginManager(object): class PluginManager(object):
""" """
@ -64,23 +65,16 @@ class PluginManager(object):
self.unload(name) self.unload(name)
try: try:
if name in self.modules: loader = finder.find_module(name)
imp.acquire_lock() if not loader:
module = imp.reload(self.modules[name]) self.core.information('Could not find plugin: %s' % name, 'Error')
imp.release_lock() return
else: module = loader.load_module()
file, filename, info = imp.find_module(name, [plugins_dir])
imp.acquire_lock()
module = imp.load_module(name, file, filename, info)
imp.release_lock()
except Exception as e: except Exception as e:
import traceback import traceback
log.debug("Could not load plugin: \n%s", traceback.format_exc()) log.debug("Could not load plugin: \n%s", traceback.format_exc())
self.core.information("Could not load plugin: %s" % e, 'Error') self.core.information("Could not load plugin: %s" % e, 'Error')
return return
finally:
if imp.lock_held():
imp.release_lock()
self.modules[name] = module self.modules[name] = module
self.commands[name] = {} self.commands[name] = {}