From 7715d5bb044f891dcf420f230726b72d1695edb6 Mon Sep 17 00:00:00 2001 From: Jan Cholasta Date: Mon, 15 Jun 2015 10:53:22 +0000 Subject: [PATCH] ipalib: Move find_modules_in_dir from util to plugable https://fedorahosted.org/freeipa/ticket/3090 Reviewed-By: Martin Babinsky --- ipalib/plugable.py | 25 +++++++++++++++++++++++-- ipalib/util.py | 22 ---------------------- 2 files changed, 23 insertions(+), 24 deletions(-) diff --git a/ipalib/plugable.py b/ipalib/plugable.py index ad662e541..74ac62bae 100644 --- a/ipalib/plugable.py +++ b/ipalib/plugable.py @@ -38,7 +38,6 @@ import textwrap import collections from config import Env -import util import text from text import _ from base import ReadOnly, NameSpace, lock, islocked, check_name @@ -61,6 +60,28 @@ def is_production_mode(obj): return obj.env.mode == 'production' +# FIXME: This function has no unit test +def find_modules_in_dir(src_dir): + """ + Iterate through module names found in ``src_dir``. + """ + if not (os.path.abspath(src_dir) == src_dir and os.path.isdir(src_dir)): + return + if os.path.islink(src_dir): + return + suffix = '.py' + for name in sorted(os.listdir(src_dir)): + if not name.endswith(suffix): + continue + pyfile = os.path.join(src_dir, name) + if not os.path.isfile(pyfile): + continue + module = name[:-len(suffix)] + if module == '__init__': + continue + yield (module, pyfile) + + class Registry(object): """A decorator that makes plugins available to the API @@ -625,7 +646,7 @@ class API(DictProxy): 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): + for (name, pyfile) in find_modules_in_dir(plugins_dir): fullname = '%s.%s' % (subpackage, name) self.log.debug('importing plugin module %r', pyfile) try: diff --git a/ipalib/util.py b/ipalib/util.py index 75797229b..649a4875f 100644 --- a/ipalib/util.py +++ b/ipalib/util.py @@ -76,28 +76,6 @@ def get_current_principal(): raise errors.CCacheError() -# FIXME: This function has no unit test -def find_modules_in_dir(src_dir): - """ - Iterate through module names found in ``src_dir``. - """ - if not (os.path.abspath(src_dir) == src_dir and os.path.isdir(src_dir)): - return - if os.path.islink(src_dir): - return - suffix = '.py' - for name in sorted(os.listdir(src_dir)): - if not name.endswith(suffix): - continue - pyfile = os.path.join(src_dir, name) - if not os.path.isfile(pyfile): - continue - module = name[:-len(suffix)] - if module == '__init__': - continue - yield (module, pyfile) - - def validate_host_dns(log, fqdn): """ See if the hostname has a DNS A/AAAA record.