summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormathieui <mathieui@mathieui.net>2012-11-22 20:16:16 +0100
committermathieui <mathieui@mathieui.net>2012-11-22 20:16:16 +0100
commitba569630f7dd9d818cc40b449716714e30e4b3d5 (patch)
treea2ae3a24c949beda2288714777592c9092918dbf
parent25de0663bc6cab271c56ae7eca452a403bc2a0de (diff)
downloadpoezio-ba569630f7dd9d818cc40b449716714e30e4b3d5.tar.gz
poezio-ba569630f7dd9d818cc40b449716714e30e4b3d5.tar.bz2
poezio-ba569630f7dd9d818cc40b449716714e30e4b3d5.tar.xz
poezio-ba569630f7dd9d818cc40b449716714e30e4b3d5.zip
Revert "Fix #2151 (cannot reload the OTR plugin)"
Importlib is utterly broken in python < 3.3, So revert for now This reverts commit a1c3d0dcdf0b202cbf861c27b04cb8630b68f89f. Conflicts: src/plugin_manager.py
-rw-r--r--src/plugin_manager.py27
1 files changed, 13 insertions, 14 deletions
diff --git a/src/plugin_manager.py b/src/plugin_manager.py
index 4bab84df..a1782e1b 100644
--- a/src/plugin_manager.py
+++ b/src/plugin_manager.py
@@ -5,8 +5,7 @@ the API together. Defines also a bunch of variables related to the
plugin env.
"""
-from importlib import machinery
-from sys import version_info
+import imp
import os
from os import path
import sys
@@ -44,13 +43,6 @@ default_plugin_path = path.join(path.dirname(path.dirname(__file__)), 'plugins')
sys.path.append(default_plugin_path)
sys.path.append(plugins_dir)
-PY33 = version_info[1] >= 3
-if not PY33:
- from importlib._bootstrap import _DefaultPathFinder
- finder = _DefaultPathFinder
-else:
- finder = machinery.PathFinder
-
class PluginManager(object):
"""
Plugin Manager
@@ -75,16 +67,23 @@ class PluginManager(object):
self.unload(name)
try:
- loader = finder.find_module(name)
- if not loader:
- self.core.information('Could not find plugin: %s' % name, 'Error')
- return
- module = loader.load_module(name)
+ 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, default_plugin_path])
+ imp.acquire_lock()
+ module = imp.load_module(name, file, filename, info)
+ imp.release_lock()
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] = {}