mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-02-25 18:55:28 -06:00
Copied plugin loading function from load_plugins.py to util.py; API.load_plugins() method now calls functions in util
This commit is contained in:
parent
4fe03f5e17
commit
03accc5fb3
@ -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):
|
||||
"""
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user