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])
评论列表
文章目录