Commit cb47030a authored by Wichert Akkerman's avatar Wichert Akkerman

Add support for delayed initialization of packages through a...

Add support for delayed initialization of packages through a _packages_to_initialize list on the Products package
parent 834afe79
......@@ -633,6 +633,23 @@ def install_products(app):
install_product(app, product_dir, product_name, meta_types,
folder_permissions, raise_exc=debug_mode)
# Delayed install of products-as-packages
for module_, init_func in getattr(Products, '_packages_to_initialize', []):
try:
product = App.Product.initializeProduct(module_,
module_.__name__,
module_.__path__[0],
app)
product.package_name = module_.__name__
if init_func is not None:
newContext = ProductContext(product, app, module_)
init_func(newContext)
finally:
transaction.commit()
Products._packages_to_initialize = []
Products.meta_types=Products.meta_types+tuple(meta_types)
InitializeClass(Folder.Folder)
......
......@@ -11,3 +11,8 @@
#
##############################################################################
__ac_permissions__=()
# This is used to keep track of packages which need to be initialized as
# products. These will be processed during the usual product installation
# in OFS.Application
_packages_to_initialize = []
\ No newline at end of file
......@@ -26,6 +26,7 @@ $Id$
"""
import os, sys, time
import transaction
# Allow code to tell it is run by the test framework
os.environ['ZOPETESTCASE'] = '1'
......@@ -143,26 +144,51 @@ def hasProduct(name):
'''Checks if a product can be found along Products.__path__'''
return name in [n[1] for n in get_products()]
def installProduct(name, quiet=0):
def installProduct(name, quiet=0, package=False):
'''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.InitializeClass(Folder)
if not quiet: _print('done (%.3fs)\n' % (time.time() - start))
break
if package:
# Processing of products-as-packages can be simpler; also check
# whether this has been registered with <five:registerPackage />
# and has not been loaded.
for module_, init_func in getattr(Products, '_packages_to_initialize', []):
if module_.__name__ == name:
if not quiet: _print('Installing %s ... ' % name)
try:
product = App.Product.initializeProduct(module_,
module_.__name__,
module_.__path__[0],
_theApp)
product.package_name = module_.__name__
if init_func is not None:
newContext = App.ProductContext.ProductContext(product, app, module_)
init_func(newContext)
finally:
transaction.commit()
Globals.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)
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.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 _load_control_panel():
# Loading the Control_Panel of an existing ZODB may take
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment