summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormathieui <mathieui@mathieui.net>2012-11-17 23:03:38 +0100
committermathieui <mathieui@mathieui.net>2012-11-17 23:03:38 +0100
commita1c3d0dcdf0b202cbf861c27b04cb8630b68f89f (patch)
treefddd1c0c91a55190e36956acdb24eecd76c45c2b
parentac806cbb4149cd3684b9b297667876a5dd84dc52 (diff)
downloadpoezio-a1c3d0dcdf0b202cbf861c27b04cb8630b68f89f.tar.gz
poezio-a1c3d0dcdf0b202cbf861c27b04cb8630b68f89f.tar.bz2
poezio-a1c3d0dcdf0b202cbf861c27b04cb8630b68f89f.tar.xz
poezio-a1c3d0dcdf0b202cbf861c27b04cb8630b68f89f.zip
Fix #2151 (cannot reload the OTR plugin)
We were using the deprecated imp methods, now we use importlib
-rw-r--r--src/plugin_manager.py20
1 files changed, 7 insertions, 13 deletions
diff --git a/src/plugin_manager.py b/src/plugin_manager.py
index 32cb2c03..4c3007cc 100644
--- a/src/plugin_manager.py
+++ b/src/plugin_manager.py
@@ -5,7 +5,7 @@ the API together. Defines also a bunch of variables related to the
plugin env.
"""
-import imp
+import importlib
import os
import sys
import logging
@@ -39,6 +39,7 @@ except OSError:
pass
sys.path.append(plugins_dir)
+finder = importlib.machinery.PathFinder()
class PluginManager(object):
"""
@@ -64,23 +65,16 @@ class PluginManager(object):
self.unload(name)
try:
- if name in self.modules:
- imp.acquire_lock()
- module = imp.reload(self.modules[name])
- imp.release_lock()
- else:
- file, filename, info = imp.find_module(name, [plugins_dir])
- imp.acquire_lock()
- module = imp.load_module(name, file, filename, info)
- imp.release_lock()
+ loader = finder.find_module(name)
+ if not loader:
+ self.core.information('Could not find plugin: %s' % name, 'Error')
+ return
+ module = loader.load_module()
except Exception as e:
import traceback
log.debug("Could not load plugin: \n%s", traceback.format_exc())
self.core.information("Could not load plugin: %s" % e, 'Error')
return
- finally:
- if imp.lock_held():
- imp.release_lock()
self.modules[name] = module
self.commands[name] = {}