本文整理汇总了Python中pkgutil.iter_modules方法的典型用法代码示例。如果您正苦于以下问题:Python pkgutil.iter_modules方法的具体用法?Python pkgutil.iter_modules怎么用?Python pkgutil.iter_modules使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pkgutil
的用法示例。
在下文中一共展示了pkgutil.iter_modules方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _execute_performance
# 需要导入模块: import pkgutil [as 别名]
# 或者: from pkgutil import iter_modules [as 别名]
def _execute_performance(self, naarad_obj):
"""
Executes naarad
:param naarad_obj:
:return:
"""
naarad_obj.analyze(self._logs_dir, self._output_dir)
if ('matplotlib' in [tuple_[1] for tuple_ in iter_modules()]) and len(self.configs) > 1:
prevConfig = self.configs[0]
if naarad_obj._output_directory is None:
naarad_obj._output_directory = self._output_dir
for curConfig in self.configs[1:]:
if not curConfig.naarad_id is None:
naarad_obj.diff(curConfig.naarad_id, prevConfig.naarad_id)
prevConfig = curConfig
tests = [test for test in self.tests if not isinstance(test, list)] +\
[individual_test for test in self.tests if isinstance(test, list) for individual_test in test]
for test in tests:
if test.naarad_id is not None:
test.naarad_stats = naarad_obj.get_stats_data(test.naarad_id)
test.sla_objs = self._convert_naarad_slas_to_list(naarad_obj.get_sla_data(test.naarad_id))
示例2: dynamic_load_return_mods
# 需要导入模块: import pkgutil [as 别名]
# 或者: from pkgutil import iter_modules [as 别名]
def dynamic_load_return_mods():
#---------------------------------------
# path = os.path.join(os.getcwd(), "plugins/substitutions")
path = os.path.join(os.path.dirname(__file__), "plugins/substitutions")
path = path.replace("src/pluginSystem/", "")
path = path.replace("src\pluginSystem\\", "")
modules = pkgutil.iter_modules(path=[path])
mode_names = []
for loader, mod_name, ispkg in modules:
mode_names.append(mod_name)
return mode_names
#---------------------------------------
开发者ID:kenb123,项目名称:Basic-Expression-Lexicon-Variation-Algorithms-BELVA,代码行数:20,代码来源:pluginDynamicSubstitutions.py
示例3: dynamic_load_return_mods
# 需要导入模块: import pkgutil [as 别名]
# 或者: from pkgutil import iter_modules [as 别名]
def dynamic_load_return_mods():
#---------------------------------------
#---- we want to return mod names so we can control output
# path = os.path.join(os.path.dirname(__file__), "applicationSignatures")
# path = os.path.join(os.getcwd(), "plugins/policies/mutate")
path = os.path.join(os.path.dirname(__file__), "plugins/policies/mutate")
path = path.replace("src/pluginSystem/", "")
path = path.replace("src\pluginSystem\\", "")
modules = pkgutil.iter_modules(path=[path])
mode_names = []
for loader, mod_name, ispkg in modules:
mode_names.append(mod_name)
return mode_names
#---------------------------------------
开发者ID:kenb123,项目名称:Basic-Expression-Lexicon-Variation-Algorithms-BELVA,代码行数:23,代码来源:pluginDynamicMutatePolicies.py
示例4: dynamic_load_return_mods
# 需要导入模块: import pkgutil [as 别名]
# 或者: from pkgutil import iter_modules [as 别名]
def dynamic_load_return_mods():
#---------------------------------------
# path = os.path.join(os.getcwd(), "plugins/policies/select")
path = os.path.join(os.path.dirname(__file__), "plugins/policies/select")
path = path.replace("src/pluginSystem/", "")
path = path.replace("src\pluginSystem\\", "")
modules = pkgutil.iter_modules(path=[path])
# print ""
mode_names = []
for loader, mod_name, ispkg in modules:
mode_names.append(mod_name)
return mode_names
#---------------------------------------
开发者ID:kenb123,项目名称:Basic-Expression-Lexicon-Variation-Algorithms-BELVA,代码行数:22,代码来源:pluginDynamicSelectPolicies.py
示例5: list_available_algorithms
# 需要导入模块: import pkgutil [as 别名]
# 或者: from pkgutil import iter_modules [as 别名]
def list_available_algorithms() -> List[str]:
"""
The list of available DCOP algorithms.
Returns
-------
a list of str
"""
exclude_list = {'generic_computations', 'graphs', 'objects'}
algorithms = []
root_algo = import_module('pydcop.algorithms')
for importer, modname, ispkg in pkgutil.iter_modules(root_algo.__path__,
''):
if modname not in exclude_list:
algorithms.append(modname)
return algorithms
示例6: load_submodules
# 需要导入模块: import pkgutil [as 别名]
# 或者: from pkgutil import iter_modules [as 别名]
def load_submodules(base_pkg=None):
if base_pkg is None:
import dionaea as base_pkg
prefix = base_pkg.__name__ + "."
for importer, modname, ispkg in pkgutil.iter_modules(base_pkg.__path__, prefix):
if modname in loaded_submodules:
continue
logger.info("Import module %s", modname)
try:
__import__(modname, fromlist="dummy")
except Exception as e:
logger.warning("Error loading module: {}".format(str(e)))
for msg in traceback.format_exc().split("\n"):
logger.warning(msg.rstrip())
loaded_submodules.append(modname)
示例7: load_backend
# 需要导入模块: import pkgutil [as 别名]
# 或者: from pkgutil import iter_modules [as 别名]
def load_backend(backend_name):
# Look for a fully qualified database backend name
try:
return import_module('%s.base' % backend_name)
except ImportError as e_user:
# The database backend wasn't found. Display a helpful error message
# listing all possible (built-in) database backends.
backend_dir = os.path.join(os.path.dirname(upath(__file__)), 'backends')
try:
builtin_backends = [
name for _, name, ispkg in pkgutil.iter_modules([backend_dir])
if ispkg and name != 'dummy']
except EnvironmentError:
builtin_backends = []
if backend_name not in ['django.db.backends.%s' % b for b in
builtin_backends]:
backend_reprs = map(repr, sorted(builtin_backends))
error_msg = ("%r isn't an available database backend.\n"
"Try using 'django.db.backends.XXX', where XXX "
"is one of:\n %s\nError was: %s" %
(backend_name, ", ".join(backend_reprs), e_user))
raise ImproperlyConfigured(error_msg)
else:
# If there's some other error, this must be an error in Django
raise
示例8: getunpackers
# 需要导入模块: import pkgutil [as 别名]
# 或者: from pkgutil import iter_modules [as 别名]
def getunpackers():
"""Scans the unpackers dir, finds unpackers and add them to UNPACKERS list.
An unpacker will be loaded only if it is a valid python module (name must
adhere to naming conventions) and it is not blacklisted (i.e. inserted
into BLACKLIST."""
path = __path__
prefix = __name__ + '.'
unpackers = []
interface = ['unpack', 'detect', 'PRIORITY']
for _importer, modname, _ispkg in pkgutil.iter_modules(path, prefix):
if 'tests' not in modname and modname not in BLACKLIST:
try:
module = __import__(modname, fromlist=interface)
except ImportError:
raise UnpackingError('Bad unpacker: %s' % modname)
else:
unpackers.append(module)
return sorted(unpackers, key = lambda mod: mod.PRIORITY)
示例9: _iter_all_modules
# 需要导入模块: import pkgutil [as 别名]
# 或者: from pkgutil import iter_modules [as 别名]
def _iter_all_modules(package, prefix=""):
"""
Iterates over the names of all modules that can be found in the given
package, recursively.
Example:
_iter_all_modules(_pytest) ->
['_pytest.assertion.newinterpret',
'_pytest.capture',
'_pytest.core',
...
]
"""
import os
import pkgutil
if type(package) is not str:
path, prefix = package.__path__[0], package.__name__ + "."
else:
path = package
for _, name, is_package in pkgutil.iter_modules([path]):
if is_package:
for m in _iter_all_modules(os.path.join(path, name), prefix=name + "."):
yield prefix + m
else:
yield prefix + name
示例10: _sub_modules
# 需要导入模块: import pkgutil [as 别名]
# 或者: from pkgutil import iter_modules [as 别名]
def _sub_modules(self):
"""
Lists modules in the directory of this module (if this module is a
package).
"""
path = self._module.path
names = []
if path is not None and path.endswith(os.path.sep + '__init__.py'):
mods = pkgutil.iter_modules([os.path.dirname(path)])
for module_loader, name, is_pkg in mods:
name = helpers.FakeName(name)
# It's obviously a relative import to the current module.
imp = helpers.FakeImport(name, self, level=1)
name.parent = imp
names.append(name)
return names
示例11: _get_module_names
# 需要导入模块: import pkgutil [as 别名]
# 或者: from pkgutil import iter_modules [as 别名]
def _get_module_names(self, search_path=None):
"""
Get the names of all modules in the search_path. This means file names
and not names defined in the files.
"""
names = []
# add builtin module names
if search_path is None:
names += [self._generate_name(name) for name in sys.builtin_module_names]
if search_path is None:
search_path = self._importer.sys_path_with_modifications()
for module_loader, name, is_pkg in pkgutil.iter_modules(search_path):
names.append(self._generate_name(name))
return names
示例12: load_fuzzer
# 需要导入模块: import pkgutil [as 别名]
# 或者: from pkgutil import iter_modules [as 别名]
def load_fuzzer():
""" Dynamically load the specified fuzzer
"""
load = importlib.import_module("src.fuzzers")
modules = list(pkgutil.iter_modules(load.__path__))
for mod in modules:
# pull up the module and iterate over its components,
# stop once we find the correct class to invoke.
dp = mod[0].find_module(mod[1]).load_module(mod[1])
for e in dir(dp):
x = getattr(dp, e)
if e and e != "Fuzzer" and config.SESSION_FUZZER in e and\
issubclass(x, Fuzzer):
utility.msg("Loaded fuzzer %s" % e, LOG)
return x()
return None
示例13: list_fuzzers
# 需要导入模块: import pkgutil [as 别名]
# 或者: from pkgutil import iter_modules [as 别名]
def list_fuzzers():
""" Dump all of the fuzzers currently loadable
"""
msg("Currently loaded fuzzers")
try:
load = importlib.import_module("src.fuzzers")
modules = list(pkgutil.iter_modules(load.__path__))
for mod in modules:
dp = mod[0].find_module(mod[1]).load_module(mod[1])
for e in dir(dp):
x = getattr(dp, e)
if isclass(x) and e != "Fuzzer" and issubclass(x, src.core.fuzzer.Fuzzer):
msg(" %s (%s)" % (x().name, mod[1]))
except Exception, e:
msg("Failed to list modules: %s" % e, ERROR)
示例14: load_plugins
# 需要导入模块: import pkgutil [as 别名]
# 或者: from pkgutil import iter_modules [as 别名]
def load_plugins(self, path):
"""Attempt to load plugins from the path specified.
:param path: full path to a directory where to look for plugins
"""
for loader, name, ispkg in pkgutil.iter_modules([path]):
file, pathname, desc = imp.find_module(name, [path])
# set the full plugin module name
module_name = "streamlink.plugin.{0}".format(name)
try:
self.load_plugin(module_name, file, pathname, desc)
except Exception:
sys.stderr.write("Failed to load plugin {0}:\n".format(name))
print_small_exception("load_plugin")
continue
示例15: init_plugins
# 需要导入模块: import pkgutil [as 别名]
# 或者: from pkgutil import iter_modules [as 别名]
def init_plugins(config):
import imp, pkgutil, __builtin__, os
global plugins
if __builtin__.use_local_modules:
fp, pathname, description = imp.find_module('plugins')
plugin_names = [name for a, name, b in pkgutil.iter_modules([pathname])]
plugin_names = filter( lambda name: os.path.exists(os.path.join(pathname,name+'.py')), plugin_names)
imp.load_module('chainkey_plugins', fp, pathname, description)
plugin_modules = map(lambda name: imp.load_source('chainkey_plugins.'+name, os.path.join(pathname,name+'.py')), plugin_names)
else:
import chainkey_plugins
plugin_names = [name for a, name, b in pkgutil.iter_modules(chainkey_plugins.__path__)]
plugin_modules = [ __import__('chainkey_plugins.'+name, fromlist=['chainkey_plugins']) for name in plugin_names]
for name, p in zip(plugin_names, plugin_modules):
try:
plugins.append( p.Plugin(config, name) )
except Exception:
print_msg(_("Error: cannot initialize plugin"),p)
traceback.print_exc(file=sys.stdout)