commandregistry.py 文件源码

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

项目:zoocore 作者: dsparrow27 项目源码 文件源码
def registerByPackage( pkg):
    """This function is similar to registerByModule() but works on packages, this is an expensive operation as it
    requires a recursive search by importing all sub modules and and searching them.

    :param pkg: The package path to register eg. zoo.libs.apps
    :type pkg: str
    """
    visited = set()
    commands = []
    for subModule in modules.iterModules(pkg):
        filename = os.path.splitext(os.path.basename(subModule))[0]
        if filename.startswith("__") or subModule.endswith(".pyc") or filename in visited:
            continue
        visited.add(filename)
        subModuleObj = modules.importModule(subModule)
        for member in modules.iterMembers(subModuleObj, predicate=inspect.isclass):
            newCom = registerCommand(member[1])
            if newCom:
                commands.append(newCom)
    return commands
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号