utils.py 文件源码

python
阅读 21 收藏 0 点赞 0 评论 0

项目:maltese 作者: HPE-AppliedSecurityResearch 项目源码 文件源码
def get_plugins(plugintype, module = None):
    """ Discover the plugin classes contained in Python files.
        Return a list of plugin classes.
    """
    dir = os.path.join(os.getcwd(), "plugins", plugintype.id)
    loaded = 0
    plugins = []
    for filename in os.listdir(dir):
        modname, ext = os.path.splitext(filename)
        if ext == '.py':
            file, path, descr = imp.find_module(modname, [dir])
            if file:
                if module == modname:
                # Loading the module registers the plugin in
                # the corresponding base classes
                    mod = imp.load_module(modname, file, path, descr)
                    loaded += 1
                elif not module:
                    plugins.append(modname)
                    loaded += 1
    if plugins:
        return plugins
    else:
        return plugintype.registry
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号