summaryrefslogtreecommitdiffstats
path: root/ipalib/plugable.py
diff options
context:
space:
mode:
authorJason Gerard DeRose <jderose@redhat.com>2009-02-12 02:10:12 -0700
committerRob Crittenden <rcritten@redhat.com>2009-02-17 16:03:10 -0500
commit4ab133c3cb8fa9a9aff2b7e5d1c53a0feb164f3f (patch)
tree5e1989c8c054b05876a86ed81ebb6dea6f66b033 /ipalib/plugable.py
parente0fe7323187df205c0994cc3fa4e0ee0b6445788 (diff)
downloadfreeipa-4ab133c3cb8fa9a9aff2b7e5d1c53a0feb164f3f.zip
freeipa-4ab133c3cb8fa9a9aff2b7e5d1c53a0feb164f3f.tar.gz
freeipa-4ab133c3cb8fa9a9aff2b7e5d1c53a0feb164f3f.tar.xz
Implemented more elegant way for entire plugin module to be conditionally skipped; updated cert.py and ra.py modules to use this
Diffstat (limited to 'ipalib/plugable.py')
-rw-r--r--ipalib/plugable.py38
1 files changed, 36 insertions, 2 deletions
diff --git a/ipalib/plugable.py b/ipalib/plugable.py
index 2c862a9..213b597 100644
--- a/ipalib/plugable.py
+++ b/ipalib/plugable.py
@@ -646,9 +646,43 @@ class API(DictProxy):
self.__do_if_not_done('bootstrap')
if self.env.mode in ('dummy', 'unit_test'):
return
- util.import_plugins_subpackage('ipalib')
+ self.import_plugins('ipalib')
if self.env.in_server:
- util.import_plugins_subpackage('ipaserver')
+ self.import_plugins('ipaserver')
+
+ # FIXME: This method has no unit test
+ def import_plugins(self, package):
+ """
+ Import modules in ``plugins`` sub-package of ``package``.
+ """
+ subpackage = '%s.plugins' % package
+ try:
+ parent = __import__(package)
+ plugins = __import__(subpackage).plugins
+ except ImportError, e:
+ self.log.error(
+ 'cannot import plugins sub-package %s: %s', subpackage, e
+ )
+ raise e
+ parent_dir = path.dirname(path.abspath(parent.__file__))
+ plugins_dir = path.dirname(path.abspath(plugins.__file__))
+ if parent_dir == plugins_dir:
+ raise errors2.PluginsPackageError(
+ name=subpackage, file=plugins.__file__
+ )
+ self.log.debug('importing all plugin modules in %r...', plugins_dir)
+ for (name, pyfile) in util.find_modules_in_dir(plugins_dir):
+ fullname = '%s.%s' % (subpackage, name)
+ self.log.debug('importing plugin module %r', pyfile)
+ try:
+ __import__(fullname)
+ except errors2.SkipPluginModule, e:
+ self.log.info(
+ 'skipping plugin module %s: %s', fullname, e.reason
+ )
+ except StandardError, e:
+ self.log.error('could not load plugin module %r', pyfile)
+ raise e
def finalize(self):
"""