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): ...@@ -633,6 +633,23 @@ def install_products(app):
install_product(app, product_dir, product_name, meta_types, install_product(app, product_dir, product_name, meta_types,
folder_permissions, raise_exc=debug_mode) 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) Products.meta_types=Products.meta_types+tuple(meta_types)
InitializeClass(Folder.Folder) InitializeClass(Folder.Folder)
......
...@@ -11,3 +11,8 @@ ...@@ -11,3 +11,8 @@
# #
############################################################################## ##############################################################################
__ac_permissions__=() __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$ ...@@ -26,6 +26,7 @@ $Id$
""" """
import os, sys, time import os, sys, time
import transaction
# Allow code to tell it is run by the test framework # Allow code to tell it is run by the test framework
os.environ['ZOPETESTCASE'] = '1' os.environ['ZOPETESTCASE'] = '1'
...@@ -143,26 +144,51 @@ def hasProduct(name): ...@@ -143,26 +144,51 @@ def hasProduct(name):
'''Checks if a product can be found along Products.__path__''' '''Checks if a product can be found along Products.__path__'''
return name in [n[1] for n in get_products()] 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.''' '''Installs a Zope product.'''
start = time.time() start = time.time()
meta_types = [] meta_types = []
if _patched and not _installedProducts.has_key(name): if _patched and not _installedProducts.has_key(name):
for priority, product_name, index, product_dir in get_products(): if package:
if product_name == name: # Processing of products-as-packages can be simpler; also check
if not quiet: _print('Installing %s ... ' % product_name) # whether this has been registered with <five:registerPackage />
# We want to fail immediately if a product throws an exception # and has not been loaded.
# during install, so we set the raise_exc flag. for module_, init_func in getattr(Products, '_packages_to_initialize', []):
install_product(_theApp, product_dir, product_name, meta_types, if module_.__name__ == name:
get_folder_permissions(), raise_exc=1) if not quiet: _print('Installing %s ... ' % name)
_installedProducts[product_name] = 1 try:
Products.meta_types = Products.meta_types + tuple(meta_types) product = App.Product.initializeProduct(module_,
Globals.InitializeClass(Folder) module_.__name__,
if not quiet: _print('done (%.3fs)\n' % (time.time() - start)) module_.__path__[0],
break _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: else:
if name != 'SomeProduct': # Ignore the skeleton tests :-P for priority, product_name, index, product_dir in get_products():
if not quiet: _print('Installing %s ... NOT FOUND\n' % name) 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(): def _load_control_panel():
# Loading the Control_Panel of an existing ZODB may take # 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