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