summaryrefslogtreecommitdiffstats
path: root/ipalib
diff options
context:
space:
mode:
authorJason Gerard DeRose <jderose@redhat.com>2008-10-17 22:09:50 -0600
committerJason Gerard DeRose <jderose@redhat.com>2008-10-17 22:09:50 -0600
commit80ccf8b1c641fd6c41256fd28ea3b89c590e8d4c (patch)
tree7afe3e9b3658b9b9570a352c17ae04df5dbc65b5 /ipalib
parent721982870ed6dd5507a634d09dd06309abc3778a (diff)
downloadfreeipa-80ccf8b1c641fd6c41256fd28ea3b89c590e8d4c.tar.gz
freeipa-80ccf8b1c641fd6c41256fd28ea3b89c590e8d4c.tar.xz
freeipa-80ccf8b1c641fd6c41256fd28ea3b89c590e8d4c.zip
Reworked load_plugins so it doesn't use imp.load_module() to load from the plugins/ sub-packages, which previously caused them to be loaded multiple times when runnig the doctests
Diffstat (limited to 'ipalib')
-rw-r--r--ipalib/load_plugins.py37
1 files changed, 23 insertions, 14 deletions
diff --git a/ipalib/load_plugins.py b/ipalib/load_plugins.py
index 4352ac651..4e02f5bab 100644
--- a/ipalib/load_plugins.py
+++ b/ipalib/load_plugins.py
@@ -33,9 +33,9 @@ import imp
import inspect
-def load_plugins(src_dir):
+def find_modules_in_dir(src_dir):
"""
- Import each Python module found in ``src_dir``.
+ Iterate through module names found in ``src_dir``.
"""
if not (path.abspath(src_dir) == src_dir and path.isdir(src_dir)):
return
@@ -51,23 +51,32 @@ def load_plugins(src_dir):
module = name[:-len(suffix)]
if module == '__init__':
continue
+ yield module
+
+
+def load_plugins_in_dir(src_dir):
+ """
+ Import each Python module found in ``src_dir``.
+ """
+ for module in find_modules_in_dir(src_dir):
imp.load_module(module, *imp.find_module(module, [src_dir]))
-def load_plugins_subpackage(file_in_package):
+def import_plugins(name):
"""
- Load all Python modules found in a plugins/ subpackage.
+ Load all plugins found in standard 'plugins' sub-package.
"""
- package_dir = path.dirname(path.abspath(file_in_package))
- plugins_dir = path.join(package_dir, 'plugins')
- load_plugins(plugins_dir)
+ try:
+ plugins = __import__(name + '.plugins').plugins
+ except ImportError:
+ return
+ src_dir = path.dirname(path.abspath(plugins.__file__))
+ for name in find_modules_in_dir(src_dir):
+ full_name = '%s.%s' % (plugins.__name__, name)
+ __import__(full_name)
-load_plugins_subpackage(__file__)
-try:
- import ipa_server
- load_plugins_subpackage(ipa_server.__file__)
-except ImportError:
- pass
+for name in ['ipalib', 'ipa_server', 'ipa_not_a_package']:
+ import_plugins(name)
-load_plugins(path.expanduser('~/.freeipa'))
+load_plugins_in_dir(path.expanduser('~/.freeipa'))