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 install_deferred(): # Temporarily patch fiveconfigure with findProducts able to see only # products under reload paths and execute Five configuration directives import sauna.reload import Products.Five.fiveconfigure setattr(Products.Five.fiveconfigure, "findProducts", findDeferredProducts) load_config("fiveconfigure.zcml", sauna.reload) setattr(Products.Five.fiveconfigure, "findProducts", findProducts) # Five pushes old-style product initializations into # Products._packages_to_initialize-list. We must loop through that list # for our reloaded packages and try to install them. import Products from App.config import getConfiguration from OFS.Application import install_package from Zope2.App.startup import app # FIXME: Is this really the only way to get our app-object? app = app() # XXX: Help! Should we use use app._p_jar-stuff around here? debug_mode = getConfiguration().debug_mode from sauna.reload import reload_paths for module, init_func in getattr(Products, "_packages_to_initialize", []): if getattr(module, "__file__") in reload_paths: install_package(app, module, init_func, raise_exc=debug_mode) if hasattr(Products, "_packages_to_initialize"): del Products._packages_to_initialize
def _install_package(self, name, app): """Zope 2 install a given package. """ if name not in self.installed_packages: for module, init_func in get_packages_to_initialize(): if module.__name__ == name: install_package(app, module, init_func, raise_exc=1) self.installed_packages.append(name) break
def setUpZope(self, app, configurationContext): """Set up Zope.""" # Load ZCML import stxnext.grayscale self.loadZCML(package=stxnext.grayscale) from OFS.Application import install_package install_package(app, stxnext.grayscale, stxnext.grayscale.initialize)
def installDeferred(): """ Temporarily patch fiveconfigure with a findProducts-method, which is able to see only the products under the reload paths and execute Five configuration directives for those. """ import sauna.reload try: # Zope 2.13 import OFS.metaconfigure setattr(OFS.metaconfigure, 'findProducts', findDeferredProducts) load_config('fiveconfigure.zcml', sauna.reload) setattr(OFS.metaconfigure, 'findProducts', findProducts) except ImportError: # Zope 2.12 import Products.Five.fiveconfigure setattr(Products.Five.fiveconfigure, 'findProducts', findDeferredProducts) load_config('fiveconfigure.zcml', sauna.reload) setattr(Products.Five.fiveconfigure, 'findProducts', findProducts) # Five pushes old-style product initializations into # Products._packages_to_initialize-list. # We must loop through that list to find the reloaded packages # and try to install them when found. from App.config import getConfiguration from OFS.Application import install_package from Zope2.App.startup import app app = app() debug_mode = getConfiguration().debug_mode from sauna.reload import reload_paths try: # Zope 2.13 import OFS.metaconfigure # We iterate a copy of packages_to_initialize, # because install_package mutates the original. packages_to_initialize = [ info for info in getattr(OFS.metaconfigure, '_packages_to_initialize', []) ] for module, init_func in packages_to_initialize: if getattr(module, '__file__') in reload_paths: install_package(app, module, init_func, raise_exc=debug_mode) except ImportError: # Zope 2.12 import Products # We iterate a copy of packages_to_initialize, # because install_package mutates the original. packages_to_initialize = [ info for info in getattr(Products, '_packages_to_initialize', []) ] for module, init_func in packages_to_initialize: if getattr(module, '__file__') in reload_paths: install_package(app, module, init_func, raise_exc=debug_mode) if hasattr(Products, '_packages_to_initialize'): del Products._packages_to_initialize
def setUpZope(self, app, configurationContext): """ Set up Zope """ # Load ZCML import collective.pwexpiry self.loadZCML(package=collective.pwexpiry) self.loadZCML(package=collective.pwexpiry, name='overrides.zcml') from OFS.Application import install_package install_package(app, collective.pwexpiry, collective.pwexpiry.initialize)
def installDeferred(): """ Temporarily patch fiveconfigure with a findProducts-method, which is able to see only the products under the reload paths and execute Five configuration directives for those. """ import sauna.reload try: # Zope 2.13 import OFS.metaconfigure setattr(OFS.metaconfigure, 'findProducts', findDeferredProducts) load_config('fiveconfigure.zcml', sauna.reload) setattr(OFS.metaconfigure, 'findProducts', findProducts) except ImportError: # Zope 2.12 import Products.Five.fiveconfigure setattr(Products.Five.fiveconfigure, 'findProducts', findDeferredProducts) load_config('fiveconfigure.zcml', sauna.reload) setattr(Products.Five.fiveconfigure, 'findProducts', findProducts) # Five pushes old-style product initializations into # Products._packages_to_initialize-list. # We must loop through that list to find the reloaded packages # and try to install them when found. from App.config import getConfiguration from OFS.Application import install_package from Zope2.App.startup import app app = app() debug_mode = getConfiguration().debug_mode from sauna.reload import reload_paths try: # Zope 2.13 import OFS.metaconfigure # We iterate a copy of packages_to_initialize, # because install_package mutates the original. packages_to_initialize = [info for info in getattr( OFS.metaconfigure, '_packages_to_initialize', [])] for module, init_func in packages_to_initialize: if getattr(module, '__file__') in reload_paths: install_package(app, module, init_func, raise_exc=debug_mode) except ImportError: # Zope 2.12 import Products # We iterate a copy of packages_to_initialize, # because install_package mutates the original. packages_to_initialize = [info for info in getattr( Products, '_packages_to_initialize', [])] for module, init_func in packages_to_initialize: if getattr(module, '__file__') in reload_paths: install_package(app, module, init_func, raise_exc=debug_mode) if hasattr(Products, '_packages_to_initialize'): del Products._packages_to_initialize
def afterSetUp(self): PloneTestCase.PloneTestCase.afterSetUp(self) install_package(self.app, plonesocial.auth.rpx, plonesocial.auth.rpx.initialize) self.acl_users = self.portal.acl_users self.portal.portal_quickinstaller.installProduct("plonesocial.auth.rpx") portal_properties = getToolByName(self.portal, 'portal_properties') self.props = portal_properties.site_properties # sessioning setup if 'session_data_manager' in self.app.objectIds(): self.app._delObject('session_data_manager') self.app._setObject('session_data_manager', DummySessionDataManager())
def afterSetUp(self): PloneTestCase.PloneTestCase.afterSetUp(self) install_package(self.app, plonesocial.auth.rpx, plonesocial.auth.rpx.initialize) self.acl_users = self.portal.acl_users self.portal.portal_quickinstaller.installProduct( "plonesocial.auth.rpx") portal_properties = getToolByName(self.portal, 'portal_properties') self.props = portal_properties.site_properties # sessioning setup if 'session_data_manager' in self.app.objectIds(): self.app._delObject('session_data_manager') self.app._setObject('session_data_manager', DummySessionDataManager())
def setUp(cls): fiveconfigure.debug_mode = True zcml.load_config('configure.zcml', Products.Gloworm) #fiveconfigure.debug_mode = True # starting with 2.10.4 product initialization gets delayed for # instance startup and is never called when running tests; hence # we have to initialize the package method manually... from OFS.Application import install_package app = ztc.app() install_package(app, Products.Gloworm, Products.Gloworm.initialize) # create a starting point for the tests... commit() ztc.close(app)
def _installPackage(name, quiet=0): '''Installs a registered Python package.''' from OFS.metaconfigure import get_packages_to_initialize start = time.time() if _patched and not _installedPackages.has_key(name): for module, init_func in get_packages_to_initialize(): if module.__name__ == name: if not quiet: _print('Installing %s ... ' % module.__name__) install_package(_theApp, module, init_func) _installedPackages[module.__name__] = 1 if not quiet: _print('done (%.3fs)\n' % (time.time() - start)) break else: if not quiet: _print('Installing %s ... NOT FOUND\n' % name)
def _installPackage(name, quiet=0): '''Installs a registered Python package.''' from OFS.metaconfigure import get_packages_to_initialize start = time.time() if _patched and not _installedPackages.has_key(name): for module, init_func in get_packages_to_initialize(): if module.__name__ == name: if not quiet: _print('Installing %s ... ' % module.__name__) # We want to fail immediately if a package throws an exception # during install, so we set the raise_exc flag. install_package(_theApp, module, init_func, raise_exc=1) _installedPackages[module.__name__] = 1 if not quiet: _print('done (%.3fs)\n' % (time.time() - start)) break else: if not quiet: _print('Installing %s ... NOT FOUND\n' % name)
def installPackage(name, quiet=0): '''Installs a registered Python package like a Zope product.''' start = time.time() if _patched and not _installedPackages.has_key(name): for module, init_func in getattr(Products, '_packages_to_initialize', []): if module.__name__ == name: if not quiet: _print('Installing %s ... ' % module.__name__) # We want to fail immediately if a package throws an exception # during install, so we set the raise_exc flag. install_package(_theApp, module, init_func, raise_exc=1) _installedPackages[module.__name__] = 1 Products._packages_to_initialize.remove((module, init_func)) if not quiet: _print('done (%.3fs)\n' % (time.time() - start)) break else: if not quiet: _print('Installing %s ... NOT FOUND\n' % name)
def setup_ContentWellPortlets(): """The @onsetup decorator means this will not execute until the Plone site testing layer has been set up """ # Load the ZCML configuration fiveconfigure.debug_mode = True import Products.ContentWellPortlets zcml.load_config('configure.zcml', Products.ContentWellPortlets) fiveconfigure.debug_mode = False # Make the product available. # Note: ztc.installPackage('Products.ContentWellPortlets') yielded # "Installing Products.ContentWellPortlets ... NOT FOUND" # Therefore did it this way instead from OFS.Application import install_package app = ztc.app() install_package(app, Products.ContentWellPortlets, Products.ContentWellPortlets.initialize)
def setup_ContentWellPortlets(): """ The @onsetup decorator means this will not execute until the Plone site testing layer has been set up """ # Load the ZCML configuration fiveconfigure.debug_mode = True import Products.ContentWellPortlets zcml.load_config('configure.zcml', Products.ContentWellPortlets) fiveconfigure.debug_mode = False # Make the product available. # Note: ztc.installPackage('Products.ContentWellPortlets') yielded "Installing Products.ContentWellPortlets ... NOT FOUND" # Therefore did it this way instead from OFS.Application import install_package app = ztc.app() install_package(app, Products.ContentWellPortlets, Products.ContentWellPortlets.initialize)
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 afterSetUp(self): import pas.plugins.suisseid # Since Zope 2.10.4 we need to install our package manually install_package(self.app, pas.plugins.suisseid, pas.plugins.suisseid.initialize)
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()
def afterSetUp(self): # Since Zope 2.10.4 we need to install our package manually install_package(self.app, plonesocial.auth.rpx, plonesocial.auth.rpx.initialize)
def afterSetUp(self): ptc.PloneTestCase.afterSetUp(self) # I am ready to kill... from Zope 2.10.4 I have to do this here from OFS.Application import install_package app = ztc.app() install_package(app, upfront.versioning, upfront.versioning.initialize) self.addProfile('upfront.versioning:default') # Hack persistent utility since we need Folder to be versionable sm = self.portal.getSiteManager() utility = sm.getUtility(IVersioningSettings, 'upfront.versioning-settings') utility.versionable_types = ['Document', 'Folder', 'DDocument'] utility = getUtility(IVersioner) # Add a site member uf = self.portal.acl_users uf._doAddUser('member', 'secret', ['Member'], []) # Login as the member self.login('member') _createHomeFolder(self.portal, 'member', take_ownership=0) workspace = self.getWorkspace() # Create items in workspace as member created = [] versioned = [] for portal_type, id, version in ( ('Document', 'a-document', 1), ('Folder', 'folder-containing-item', 1), ('DDocument', 'a-ddocument', 1), ('Document', 'a-document-unversioned', 0), ('Folder', 'folder-containing-item-unversioned', 0), ('DDocument', 'a-ddocument-unversioned', 0), ): ob = _createObjectByType(portal_type, workspace, id) fti = self.portal.portal_types.getTypeInfo(portal_type) fti._finishConstruction(ob) if portal_type == 'DDocument': ob.setRelated(self.portal.news) if portal_type == 'Document': ob.setRelatedItems([self.portal.news]) created.append(ob) if version: versioned.append(ob) # Create sub-items ob = _createObjectByType('Document', workspace['folder-containing-item'], 'contained') fti = self.portal.portal_types.getTypeInfo('Document') fti._finishConstruction(ob) created.append(ob) ob = _createObjectByType('Document', workspace['folder-containing-item-unversioned'], 'contained') fti = self.portal.portal_types.getTypeInfo('Document') fti._finishConstruction(ob) created.append(ob) # Portal owner must publish the items self.loginAsPortalOwner() for ob in created: self.portal.portal_workflow.doActionFor(ob, 'publish') transaction.savepoint(optimistic=True) # Subject some items to versioning. The member still has # Modify Portal Content permission thanks to # simple_publication_workflow. self.login('member') for ob in versioned: utility.start_new_version(ob)