def test_install_product(self): self.makeProduct(os.path.join(TEMPPRODUCTS, 'abaz')) f = open(os.path.join(TEMPPRODUCTS, 'abaz', '__init__.py'), 'w') doneflag = os.path.join(TEMPPRODUCTS, 'abaz', 'doneflag') f.write(dummy_product_init % doneflag) f.close() self.configure(cfg) from OFS.Application import install_product, get_folder_permissions,\ Application import Products from OFS.Folder import Folder app = getApp() meta_types = [] install_product(app, TEMPPRODUCTS, 'abaz', meta_types, get_folder_permissions(), raise_exc=1) # misc_ dictionary is updated self.assert_(Application.misc_.__dict__.has_key('abaz')) # initialize is called self.assert_(os.path.exists(doneflag)) # Methods installed into folder self.assert_(hasattr(Folder, 'amethod')) # permission roles put into folder self.assert_(hasattr(Folder, 'amethod__roles__')) # Products.meta_types updated self.assert_( {'name': 'grabass', 'action': 'manage_addProduct/abaz/amethod', 'product': 'abaz', 'permission': 'aPermission', 'visibility': 'Global', 'interfaces': (), 'instance': None, 'container_filter': None} in Products.meta_types)
def installProduct(app, productName, quiet=False): """Install the Zope 2 product with the given name, so that it will show up in the Zope 2 control panel and have its ``initialize()`` hook called. The ``STARTUP`` layer or an equivalent layer must have been loaded first. If ``quiet`` is False, an error will be logged if the product cannot be found. By default, the function is silent. Note that products' ZCML is *not* loaded automatically, even if the product is in the Products namespace. """ import sys from OFS.Folder import Folder from OFS.Application import get_folder_permissions, get_products from OFS.Application import install_product, install_package from App.class_init import InitializeClass import Products found = False if productName in _INSTALLED_PRODUCTS: return if productName.startswith('Products.'): for priority, name, index, productDir in get_products(): if ('Products.' + name) == productName: install_product(app, productDir, name, [], get_folder_permissions(), raise_exc=1) InitializeClass(Folder) _INSTALLED_PRODUCTS[productName] = (priority, name, index, productDir,) found = True break else: if HAS_ZOPE213: packages = tuple(get_packages_to_initialize()) else: packages = getattr(Products, '_packages_to_initialize', []) for module, init_func in packages: if module.__name__ == productName: install_package(app, module, init_func, raise_exc=1) if not HAS_ZOPE213: Products._packages_to_initialize.remove((module, init_func)) _INSTALLED_PRODUCTS[productName] = (module, init_func,) found = True break if not found and not quiet: sys.stderr.write("Could not install product %s\n" % productName) sys.stderr.flush()
def _installProduct(name, quiet=0): '''Installs a Zope product.''' from AccessControl.class_init import InitializeClass start = time.time() meta_types = [] if _patched and not _installedProducts.has_key(name): for priority, product_name, index, product_dir in get_products(): if product_name == name: if not quiet: _print('Installing %s ... ' % product_name) # We want to fail immediately if a product throws an exception # during install, so we set the raise_exc flag. install_product(_theApp, product_dir, product_name, meta_types, get_folder_permissions(), raise_exc=1) _installedProducts[product_name] = 1 Products.meta_types = Products.meta_types + tuple(meta_types) InitializeClass(Folder) if not quiet: _print('done (%.3fs)\n' % (time.time() - start)) break else: if name != 'SomeProduct': # Ignore the skeleton tests :-P if not quiet: _print('Installing %s ... NOT FOUND\n' % name)
def set_package_ac_permissions(self): # Support old-old-style product metadata. Older products may # define attributes to name their permissions, meta_types, # constructors, etc. folder_permissions = get_folder_permissions() for p in pgetattr(self.package, '__ac_permissions__', ()): permission, names, default = (tuple(p) + ('Manager', ))[:3] if names: for name in names: self.permissions[name] = permission elif not folder_permissions.has_key(permission): self.new_permissions[permission] = ()
def set_package_ac_permissions(self): # Support old-old-style product metadata. Older products may # define attributes to name their permissions, meta_types, # constructors, etc. folder_permissions = get_folder_permissions() for p in pgetattr(self.package, '__ac_permissions__', ()): permission, names, default = (tuple(p) + ('Manager',))[:3] if names: for name in names: self.permissions[name] = permission elif not folder_permissions.has_key(permission): self.new_permissions[permission]=()
def _install_product(self, name, app): """Zope 2 install a given product. """ meta_types = [] if name not in self.installed_products: for priority, product_name, index, product_dir in get_products(): if product_name == name: install_product(app, product_dir, product_name, meta_types, get_folder_permissions(), raise_exc=1) self.installed_products.append(name) Products.meta_types = Products.meta_types + \ tuple(meta_types) InitializeClass(Folder) # WTF ? break
def install(self, raise_exc=True, log_exc=True): __traceback_info__ = self.productname package = self.package product = self.product productname = self.productname initializer = self.initializer permissions = self.permissions folder_permissions = get_folder_permissions() init_data = None try: self.set_package_module_aliases() self.set_package_misc_attrs() # allow entry points that are "dummies" (e.g. just the module) # in case the product doesn't have an initialize function that # needs to be called if callable(initializer): init_data = initializer(self) self.set_package_ac_permissions() self.munge_package_meta_types() self.set_package_methods() if self.new_permissions: new_permissions = self.new_permissions.items() for permission, names in new_permissions: folder_permissions[permission] = names new_permissions.sort() Folder.__ac_permissions__ = tuple( list(Folder.__ac_permissions__) + new_permissions) if not doInstall(): transaction().abort() else: transaction.get().note('Installed product ' + productname) transaction.commit() except: if log_exc: zLOG.LOG('Zope', zLOG.ERROR, 'Couldn\'t install %s' % productname, error=sys.exc_info()) transaction.abort() if raise_exc: raise return init_data
def install(self, raise_exc=True, log_exc=True): __traceback_info__ = self.productname package = self.package product = self.product productname = self.productname initializer = self.initializer permissions = self.permissions folder_permissions = get_folder_permissions() init_data = None try: self.set_package_module_aliases() self.set_package_misc_attrs() # allow entry points that are "dummies" (e.g. just the module) # in case the product doesn't have an initialize function that # needs to be called if callable(initializer): init_data = initializer(self) self.set_package_ac_permissions() self.munge_package_meta_types() self.set_package_methods() if self.new_permissions: new_permissions = self.new_permissions.items() for permission, names in new_permissions: folder_permissions[permission]=names new_permissions.sort() Folder.__ac_permissions__=tuple( list(Folder.__ac_permissions__)+new_permissions) if not doInstall(): transaction().abort() else: transaction.get().note('Installed product '+productname) transaction.commit() except: if log_exc: zLOG.LOG('Zope',zLOG.ERROR,'Couldn\'t install %s' % productname, error=sys.exc_info()) transaction.abort() if raise_exc: raise return init_data
def install_products(app, *prod): """auxiliary function to install products *prod* (by names).""" from OFS.Application import get_folder_permissions, get_products, install_product folder_permissions = get_folder_permissions() meta_types=[] done={} # work around a Zope bug: "Products.__path__" may contain # non existing elements import Products, os.path Products.__path__ = [p for p in Products.__path__ if os.path.exists(p)] products = get_products() for priority, product_name, index, product_dir in products: if product_name not in prod or product_name in done: continue done[product_name]=1 install_product(app, product_dir, product_name, meta_types, folder_permissions, raise_exc=True)
def install_products(app): # Install a list of products into the basic folder class, so # that all folders know about top-level objects, aka products # from OFS.Application import get_folder_permissions from OFS.Application import install_product from OFS.Application import install_package from OFS.Application import get_packages_to_initialize from OFS.Application import get_products from App.config import getConfiguration import transaction folder_permissions = get_folder_permissions() meta_types = [] done = {} debug_mode = getConfiguration().debug_mode transaction.get().note('Prior to product installs') transaction.commit() products = get_products() for priority, product_name, index, product_dir in products: # For each product, we will import it and try to call the # intialize() method in the product __init__ module. If # the method doesnt exist, we put the old-style information # together and do a default initialization. if product_name in done: continue if is_sauna_product(product_dir): # Will be later loaded by installDeferred() continue done[product_name] = 1 install_product(app, product_dir, product_name, meta_types, folder_permissions, raise_exc=debug_mode) # Delayed install of packages-as-products for module, init_func in tuple(get_packages_to_initialize()): install_package(app, module, init_func, raise_exc=debug_mode)
def installProduct(name, quiet=0): '''Installs a Zope product.''' start = time.time() meta_types = [] if _patched and not _installedProducts.has_key(name): for priority, product_name, index, product_dir in get_products(): if product_name == name: if not quiet: _print('Installing %s ... ' % product_name) # We want to fail immediately if a product throws an exception # during install, so we set the raise_exc flag. install_product(_theApp, product_dir, product_name, meta_types, get_folder_permissions(), raise_exc=1) _installedProducts[product_name] = 1 Products.meta_types = Products.meta_types + tuple(meta_types) Globals.default__class_init__(Folder) if not quiet: _print('done (%.3fs)\n' % (time.time() - start)) break else: if name != 'SomeProduct': # Ignore the skeleton tests :-P if not quiet: _print('Installing %s ... NOT FOUND\n' % name)
def _installProduct(name, quiet=0): '''Installs a Zope product.''' from AccessControl.class_init import InitializeClass start = time.time() meta_types = [] if _patched and not _installedProducts.has_key(name): for priority, product_name, index, product_dir in get_products(): if product_name == name: if not quiet: _print('Installing %s ... ' % product_name) install_product(_theApp, product_dir, product_name, meta_types, get_folder_permissions()) _installedProducts[product_name] = 1 Products.meta_types = Products.meta_types + tuple(meta_types) InitializeClass(Folder) if not quiet: _print('done (%.3fs)\n' % (time.time() - start)) break else: if name != 'SomeProduct': # Ignore the skeleton tests :-P if not quiet: _print('Installing %s ... NOT FOUND\n' % name)
def install_products(app, *prod): """auxiliary function to install products *prod* (by names).""" from OFS.Application import get_folder_permissions, get_products, install_product folder_permissions = get_folder_permissions() meta_types = [] done = {} # work around a Zope bug: "Products.__path__" may contain # non existing elements import Products, os.path Products.__path__ = [p for p in Products.__path__ if os.path.exists(p)] products = get_products() for priority, product_name, index, product_dir in products: if product_name not in prod or product_name in done: continue done[product_name] = 1 install_product(app, product_dir, product_name, meta_types, folder_permissions, raise_exc=True)
def _installProduct(name, quiet=0): '''Installs a Zope product.''' from AccessControl.class_init import InitializeClass start = time.time() meta_types = [] if _patched and name not in _installedProducts: for priority, product_name, index, product_dir in get_products(): if product_name == name: if not quiet: _print('Installing %s ... ' % product_name) install_product(_theApp, product_dir, product_name, meta_types, get_folder_permissions()) _installedProducts[product_name] = 1 Products.meta_types = Products.meta_types + tuple(meta_types) InitializeClass(Folder) if not quiet: _print('done (%.3fs)\n' % (time.time() - start)) break else: if name != 'SomeProduct': # Ignore the skeleton tests :-P if not quiet: _print('Installing %s ... NOT FOUND\n' % name)
def test_install_product(self): self.makeProduct(os.path.join(TEMPPRODUCTS, 'abaz')) f = open(os.path.join(TEMPPRODUCTS, 'abaz', '__init__.py'), 'w') doneflag = os.path.join(TEMPPRODUCTS, 'abaz', 'doneflag') f.write(dummy_product_init % doneflag) f.close() self.configure(cfg) from OFS.Application import install_product, get_folder_permissions,\ Application import Products from OFS.Folder import Folder app = getApp() meta_types = [] install_product(app, TEMPPRODUCTS, 'abaz', meta_types, get_folder_permissions(), raise_exc=1) # misc_ dictionary is updated self.assert_(Application.misc_.__dict__.has_key('abaz')) # initialize is called self.assert_(os.path.exists(doneflag)) # Methods installed into folder self.assert_(hasattr(Folder, 'amethod')) # permission roles put into folder self.assert_(hasattr(Folder, 'amethod__roles__')) # Products.meta_types updated self.assert_({ 'name': 'grabass', 'action': 'manage_addProduct/abaz/amethod', 'product': 'abaz', 'permission': 'aPermission', 'visibility': 'Global', 'interfaces': (), 'instance': None, 'container_filter': None } in Products.meta_types)
def installProduct(app, productName, quiet=False, multiinit=False): """Install the Zope 2 product with the given name, so that it will show up in the Zope 2 control panel and have its ``initialize()`` hook called. The ``STARTUP`` layer or an equivalent layer must have been loaded first. If ``quiet`` is False, an error will be logged if the product cannot be found. By default, the function is silent. Note that products' ZCML is *not* loaded automatically, even if the product is in the Products namespace. """ from App.class_init import InitializeClass from OFS.Application import get_folder_permissions from OFS.Application import get_products from OFS.Application import install_package from OFS.Application import install_product from OFS.Folder import Folder import Products import sys found = False if productName in _INSTALLED_PRODUCTS: return if productName.startswith('Products.'): for priority, name, index, productDir in get_products(): if ('Products.' + name) == productName: install_product(app, productDir, name, [], get_folder_permissions(), raise_exc=1) InitializeClass(Folder) _INSTALLED_PRODUCTS[productName] = ( priority, name, index, productDir, ) found = True break else: if HAS_ZOPE213: packages = tuple(get_packages_to_initialize()) else: packages = getattr(Products, '_packages_to_initialize', []) for module, init_func in packages: if module.__name__ == productName: install_package(app, module, init_func, raise_exc=1) if not HAS_ZOPE213: Products._packages_to_initialize.remove( (module, init_func)) _INSTALLED_PRODUCTS[productName] = ( module, init_func, ) found = True if not multiinit: break if not found and not quiet: sys.stderr.write("Could not install product %s\n" % productName) sys.stderr.flush()