-# Copyright 2015 Intel Corporation.
+# Copyright 2015-2017 Intel Corporation.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
import imp
import fnmatch
import logging
+from conf import settings
class LoaderServant(object):
interface=self._interface)
results = []
- for (name, mod) in list(out.items()):
+ # sort modules to produce the same output everytime
+ for (name, mod) in sorted(out.items()):
desc = (mod.__doc__ or 'No description').strip().split('\n')[0]
results.append((name, desc))
- output = [
- 'Classes derived from: ' + self._interface.__name__ + '\n======\n']
+ header = 'Classes derived from: ' + self._interface.__name__
+ output = [header + '\n' + '=' * len(header) + '\n']
for (name, desc) in results:
output.append('* %-18s%s' % ('%s:' % name, desc))
result = {}
for _, mod in LoaderServant._load_all_modules(path):
- # find all system metric loggers defined in the module
+ # find all classes derived from given interface, but suppress
+ # interface itself and any abstract class starting with iface name
gens = dict((k, v) for (k, v) in list(mod.__dict__.items())
- if type(v) == type and
- issubclass(v, interface) and k != interface.__name__)
+ if isinstance(v, type) and
+ issubclass(v, interface) and
+ not k.startswith(interface.__name__))
if gens:
for (genname, gen) in list(gens.items()):
result[genname] = gen
for filename in fnmatch.filter(filenames, '[!.]*.py'):
modname = os.path.splitext(os.path.basename(filename))[0]
+ # skip module load if it is excluded by configuration
+ if modname in settings.getValue('EXCLUDE_MODULES'):
+ continue
+
try:
if modname in sys.modules:
mod = sys.modules[modname]