[Zope-Checkins] SVN: Zope/branches/2.10/lib/python/ Add support for
delayed initialization of packages through a
_packages_to_initialize list on the Products package
Wichert Akkerman
wichert at wiggy.net
Sun Jun 17 15:04:58 EDT 2007
Log message for revision 76743:
Add support for delayed initialization of packages through a _packages_to_initialize list on the Products package
Changed:
U Zope/branches/2.10/lib/python/OFS/Application.py
U Zope/branches/2.10/lib/python/Products/__init__.py
U Zope/branches/2.10/lib/python/Testing/ZopeTestCase/ZopeLite.py
-=-
Modified: Zope/branches/2.10/lib/python/OFS/Application.py
===================================================================
--- Zope/branches/2.10/lib/python/OFS/Application.py 2007-06-17 18:25:12 UTC (rev 76742)
+++ Zope/branches/2.10/lib/python/OFS/Application.py 2007-06-17 19:04:57 UTC (rev 76743)
@@ -633,6 +633,23 @@
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)
Modified: Zope/branches/2.10/lib/python/Products/__init__.py
===================================================================
--- Zope/branches/2.10/lib/python/Products/__init__.py 2007-06-17 18:25:12 UTC (rev 76742)
+++ Zope/branches/2.10/lib/python/Products/__init__.py 2007-06-17 19:04:57 UTC (rev 76743)
@@ -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
Modified: Zope/branches/2.10/lib/python/Testing/ZopeTestCase/ZopeLite.py
===================================================================
--- Zope/branches/2.10/lib/python/Testing/ZopeTestCase/ZopeLite.py 2007-06-17 18:25:12 UTC (rev 76742)
+++ Zope/branches/2.10/lib/python/Testing/ZopeTestCase/ZopeLite.py 2007-06-17 19:04:57 UTC (rev 76743)
@@ -26,6 +26,7 @@
"""
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 @@
'''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
More information about the Zope-Checkins
mailing list