Commit 226712e2 authored by Hanno Schlichting's avatar Hanno Schlichting

Added a new API ``get_packages_to_initialize`` to ``OFS.metaconfigure``. This...

Added a new API ``get_packages_to_initialize`` to ``OFS.metaconfigure``. This replaces any direct access to ``Products._packages_to_initialize``. The OFS.Application.install_package function takes care of removing entries from this list now.
parent 47287299
......@@ -18,6 +18,11 @@ Bugs Fixed
Features Added
++++++++++++++
- Added a new API ``get_packages_to_initialize`` to ``OFS.metaconfigure``.
This replaces any direct access to ``Products._packages_to_initialize``.
The OFS.Application.install_package function takes care of removing entries
from this list now.
- Added notification of ``IDatabaseOpenedWithRoot``.
- Added a new API's ``get_registered_packages, set_registered_packages`` to
......
......@@ -34,6 +34,8 @@ from App import FactoryDispatcher
from App.Product import doInstall
from DateTime import DateTime
from HelpSys.HelpSys import HelpSys
from OFS.metaconfigure import get_packages_to_initialize
from OFS.metaconfigure import package_initialized
from OFS.userfolder import UserFolder
from Persistence import Persistent
from webdav.NullResource import NullResource
......@@ -535,10 +537,8 @@ def install_products(app):
folder_permissions, raise_exc=debug_mode)
# Delayed install of packages-as-products
for module, init_func in getattr(Products, '_packages_to_initialize', []):
for module, init_func in get_packages_to_initialize():
install_package(app, module, init_func, raise_exc=debug_mode)
if hasattr(Products, '_packages_to_initialize'):
del Products._packages_to_initialize
Products.meta_types=Products.meta_types+tuple(meta_types)
InitializeClass(Folder.Folder)
......@@ -724,6 +724,8 @@ def install_package(app, module, init_func, raise_exc=False, log_exc=True):
newContext = ProductContext(product, app, module)
init_func(newContext)
package_initialized(module, init_func)
if do_install:
transaction.get().note('Installed package %s' % module.__name__)
transaction.commit()
......
......@@ -13,6 +13,7 @@ import Products
debug_mode = App.config.getConfiguration().debug_mode
logger = logging.getLogger('OFS')
_packages_to_initialize = []
_register_monkies = []
_registered_packages = []
_meta_type_regs = []
......@@ -86,6 +87,16 @@ def has_package(package):
return package in [m.__name__ for m in get_registered_packages()]
def get_packages_to_initialize():
global _packages_to_initialize
return _packages_to_initialize
def package_initialized(module, init_func):
global _packages_to_initialize
_packages_to_initialize.remove((module, init_func))
def _registerPackage(module_, init_func=None):
"""Registers the given python package as a Zope 2 style product
"""
......@@ -100,9 +111,7 @@ def _registerPackage(module_, init_func=None):
# OFS.Application. Otherwise, we may get database write errors in
# ZEO, when there's no connection with which to write an entry to
# Control_Panel. We would also get multiple calls to initialize().
to_initialize = getattr(Products, '_packages_to_initialize', None)
if to_initialize is None:
to_initialize = Products._packages_to_initialize = []
to_initialize = get_packages_to_initialize()
to_initialize.append((module_, init_func,))
......@@ -181,6 +190,9 @@ def cleanUp():
unregisterClass(class_)
_register_monkies = []
global _packages_to_initialize
_packages_to_initialize = []
global _registered_packages
_registered_packages = []
......
......@@ -201,17 +201,18 @@ def installPackage(name, quiet=0):
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 getattr(Products, '_packages_to_initialize', []):
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
Products._packages_to_initialize.remove((module, init_func))
if not quiet: _print('done (%.3fs)\n' % (time.time() - start))
if not quiet:
_print('done (%.3fs)\n' % (time.time() - start))
break
else:
if not quiet: _print('Installing %s ... NOT FOUND\n' % name)
......
......@@ -18,15 +18,11 @@ $Id$
import sys
from unittest import TestSuite
from OFS.metaconfigure import get_registered_packages
from OFS.metaconfigure import set_registered_packages
from Testing import ZopeTestCase
from Testing.ZopeTestCase import ZopeLite
from Testing.ZopeTestCase import ZopeDocTestSuite
from Zope2.App import zcml
from zope.testing import cleanup
import Products
def testInstallPackage():
......@@ -56,23 +52,11 @@ def testInstallPackage():
>>> ZopeTestCase.hasPackage('testpackage')
True
But not yet installed
>>> app = self._app()
>>> 'testpackage' in app.Control_Panel.Products.objectIds()
False
Install it
>>> ZopeTestCase.installPackage('testpackage', quiet=True)
testpackage.initialize called
Now it shows up in Control_Panel
>>> app = self._app()
>>> 'testpackage' in app.Control_Panel.Products.objectIds()
True
hasPackage still returns True
>>> ZopeTestCase.hasPackage('testpackage')
......@@ -98,15 +82,6 @@ class TestClass(ZopeTestCase.FunctionalTestCase):
cleanup.cleanUp()
sys.path[:] = self.saved
registered = get_registered_packages()
packages = [m for m in registered if m.__name__ != 'testpackage']
set_registered_packages(packages)
to_initialize = getattr(Products, '_packages_to_initialize', None)
if to_initialize is not None:
Products._packages_to_initialize = [(m, f) for (m, f) in to_initialize
if m.__name__ != 'testpackage']
def test_suite():
if ZopeLite.active:
......@@ -115,4 +90,3 @@ def test_suite():
))
else:
return TestSuite()
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