本文整理汇总了Python中library.Library.add方法的典型用法代码示例。如果您正苦于以下问题:Python Library.add方法的具体用法?Python Library.add怎么用?Python Library.add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类library.Library
的用法示例。
在下文中一共展示了Library.add方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: package
# 需要导入模块: from library import Library [as 别名]
# 或者: from library.Library import add [as 别名]
def package(name, type, title, order, layer, library, require):
global _libraries, _packages
sm = getGlobalSiteManager()
# create marker interface
marker = _libraries.get((library, type))
if marker is None:
uid = str(random.randint(0, 9999999))
marker = InterfaceClass('IPackage%s'%uid, (interface.Interface,),
__doc__='Package: %s' %name,
__module__='zojax.resourcepackage')
_libraries[(library, type)] = marker
# check if package already registered
packageInfo = None
for (_layer, _library, _type), _packageInfo in _packages.items():
if _library == library and layer.isOrExtends(_layer) and _type == type:
packageInfo = _packageInfo
if packageInfo is not None:
# register library
if library:
lib = sm.queryUtility(ILibrary, name=library)
if lib is None:
lib = Library(library)
handler('registerUtility', lib, ILibrary, library)
lib.add(name, require)
return
# create package
package = getUtility(IPackageFactory, type)(name, order, title)
interface.directlyProvides(package, marker)
factory = Factory(package)
# register resource
sm.registerAdapter(factory, (layer, ), interface.Interface, name)
sm.registerAdapter(factory, (layer, ), IPackage, name)
# register package info
packageInfo = PackageInfo(library, layer, marker, package)
_packages[(layer, library, type)] = packageInfo
# register library
if library:
lib = sm.queryUtility(ILibrary, name=library)
if lib is None:
lib = Library(library)
handler('registerUtility', lib, ILibrary, library)
lib.add(name, require)