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,11 +144,36 @@ def hasProduct(name): ...@@ -143,11 +144,36 @@ 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):
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:
for priority, product_name, index, product_dir in get_products(): for priority, product_name, index, product_dir in get_products():
if product_name == name: if product_name == name:
if not quiet: _print('Installing %s ... ' % product_name) if not quiet: _print('Installing %s ... ' % product_name)
......
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