pluginmanager.py 文件源码

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

项目:zoocore 作者: dsparrow27 项目源码 文件源码
def registerByPackage(self, 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
        """
        mod = modules.importModule(pkg)
        realPath = os.path.dirname(inspect.getfile(mod))
        pkgSplitPath = pkg.replace(".", os.path.sep)
        self.basePaths.append(realPath)

        for subModule in modules.iterModules(realPath):
            filename = os.path.splitext(os.path.basename(subModule))[0]
            if filename.startswith("__") or subModule.endswith(".pyc"):
                continue
            newDottedPath = pkg + subModule.split(pkgSplitPath)[-1].replace(os.path.sep, ".").split(".py")[0]
            subModuleObj = modules.importModule(newDottedPath)
            for member in modules.iterMembers(subModuleObj, predicate=inspect.isclass):
                self.registerPlugin(member[1])
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号