diff options
author | Jason Gerard DeRose <jderose@redhat.com> | 2008-10-27 00:23:43 -0600 |
---|---|---|
committer | Jason Gerard DeRose <jderose@redhat.com> | 2008-10-27 00:23:43 -0600 |
commit | 03accc5fb382777d9bbdb245f3211d5c06489f6e (patch) | |
tree | 2c87504ed56d60a688bd6f7110ed1393cfee6905 /ipalib | |
parent | 4fe03f5e17dfe9d4478a75dfada2282535c989fe (diff) | |
download | freeipa-03accc5fb382777d9bbdb245f3211d5c06489f6e.tar.gz freeipa-03accc5fb382777d9bbdb245f3211d5c06489f6e.tar.xz freeipa-03accc5fb382777d9bbdb245f3211d5c06489f6e.zip |
Copied plugin loading function from load_plugins.py to util.py; API.load_plugins() method now calls functions in util
Diffstat (limited to 'ipalib')
-rw-r--r-- | ipalib/plugable.py | 5 | ||||
-rw-r--r-- | ipalib/util.py | 51 |
2 files changed, 56 insertions, 0 deletions
diff --git a/ipalib/plugable.py b/ipalib/plugable.py index 4c0b175f5..367211576 100644 --- a/ipalib/plugable.py +++ b/ipalib/plugable.py @@ -30,6 +30,7 @@ import inspect import errors from errors import check_type, check_isinstance from config import Environment +import util class ReadOnly(object): @@ -744,6 +745,10 @@ class API(DictProxy): """ self.__doing('load_plugins') self.__do_if_not_done('bootstrap') + if dry_run: + return + util.import_plugins_subpackage('ipalib') + util.import_plugins_subpackage('ipa_server') def finalize(self): """ diff --git a/ipalib/util.py b/ipalib/util.py index 184c6d7c4..d7e2c2a4b 100644 --- a/ipalib/util.py +++ b/ipalib/util.py @@ -20,7 +20,11 @@ """ Various utility functions. """ + import krbV +import os +from os import path +import imp def xmlrpc_marshal(*args, **kw): """ @@ -41,6 +45,7 @@ def xmlrpc_unmarshal(*params): kw = {} return (params[1:], kw) + def get_current_principal(): try: return krbV.default_context().default_ccache().principal().name @@ -48,3 +53,49 @@ def get_current_principal(): #TODO: do a kinit print "Unable to get kerberos principal" return None + + +# FIXME: This function has no unit test +def find_modules_in_dir(src_dir): + """ + Iterate through module names found in ``src_dir``. + """ + if not (path.abspath(src_dir) == src_dir and path.isdir(src_dir)): + return + if path.islink(src_dir): + return + suffix = '.py' + for name in sorted(os.listdir(src_dir)): + if not name.endswith(suffix): + continue + py_file = path.join(src_dir, name) + if path.islink(py_file) or not path.isfile(py_file): + continue + module = name[:-len(suffix)] + if module == '__init__': + continue + yield module + + +# FIXME: This function has no unit test +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])) + + +# FIXME: This function has no unit test +def import_plugins_subpackage(name): + """ + Import everythig in ``plugins`` sub-package of package named ``name``. + """ + 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) |