Log message for revision 113940:
  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.
  

Changed:
  U   Zope/trunk/doc/CHANGES.rst
  U   Zope/trunk/src/OFS/Application.py
  U   Zope/trunk/src/OFS/metaconfigure.py
  U   Zope/trunk/src/Testing/ZopeTestCase/ZopeLite.py
  D   Zope/trunk/src/Testing/ZopeTestCase/zopedoctest/testPackageAsProduct.py
  A   Zope/trunk/src/Testing/ZopeTestCase/zopedoctest/testPackageAsProduct.py

-=-
Modified: Zope/trunk/doc/CHANGES.rst
===================================================================
--- Zope/trunk/doc/CHANGES.rst  2010-06-27 14:05:02 UTC (rev 113939)
+++ Zope/trunk/doc/CHANGES.rst  2010-06-27 14:07:11 UTC (rev 113940)
@@ -18,6 +18,11 @@
 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

Modified: Zope/trunk/src/OFS/Application.py
===================================================================
--- Zope/trunk/src/OFS/Application.py   2010-06-27 14:05:02 UTC (rev 113939)
+++ Zope/trunk/src/OFS/Application.py   2010-06-27 14:07:11 UTC (rev 113940)
@@ -34,6 +34,8 @@
 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 @@
                         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 @@
             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()

Modified: Zope/trunk/src/OFS/metaconfigure.py
===================================================================
--- Zope/trunk/src/OFS/metaconfigure.py 2010-06-27 14:05:02 UTC (rev 113939)
+++ Zope/trunk/src/OFS/metaconfigure.py 2010-06-27 14:07:11 UTC (rev 113940)
@@ -13,6 +13,7 @@
 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 @@
     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 @@
     # 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 @@
         unregisterClass(class_)
     _register_monkies = []
 
+    global _packages_to_initialize
+    _packages_to_initialize = []
+
     global _registered_packages
     _registered_packages = []
 

Modified: Zope/trunk/src/Testing/ZopeTestCase/ZopeLite.py
===================================================================
--- Zope/trunk/src/Testing/ZopeTestCase/ZopeLite.py     2010-06-27 14:05:02 UTC 
(rev 113939)
+++ Zope/trunk/src/Testing/ZopeTestCase/ZopeLite.py     2010-06-27 14:07:11 UTC 
(rev 113940)
@@ -201,17 +201,18 @@
 
 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)

Deleted: Zope/trunk/src/Testing/ZopeTestCase/zopedoctest/testPackageAsProduct.py
===================================================================
--- Zope/trunk/src/Testing/ZopeTestCase/zopedoctest/testPackageAsProduct.py     
2010-06-27 14:05:02 UTC (rev 113939)
+++ Zope/trunk/src/Testing/ZopeTestCase/zopedoctest/testPackageAsProduct.py     
2010-06-27 14:07:11 UTC (rev 113940)
@@ -1,118 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2005 Zope Foundation and Contributors.
-#
-# This software is subject to the provisions of the Zope Public License,
-# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
-# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
-# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
-# FOR A PARTICULAR PURPOSE.
-#
-##############################################################################
-"""Tests for installPackage
-
-$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():
-    """
-    Test if installPackage works.
-
-      >>> from Testing import ZopeTestCase
-      >>> from Zope2.App import zcml
-
-    Register testpackage
-
-      >>> ZopeTestCase.hasPackage('testpackage')
-      False
-
-      >>> config = '''
-      ... <configure
-      ...     xmlns:five="http://namespaces.zope.org/five";>
-      ...   <five:registerPackage
-      ...     package="testpackage"
-      ...     initialize="testpackage.initialize"
-      ...     />
-      ... </configure>'''
-      >>> zcml.load_string(config)
-
-    The package is registered now
-
-      >>> 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')
-      True
-
-    A package is only installed once, subsequent calls to installPackage
-    are ignored:
-
-      >>> ZopeTestCase.installPackage('testpackage', quiet=True)
-    """
-
-
-class TestClass(ZopeTestCase.FunctionalTestCase):
-
-    def afterSetUp(self):
-        cleanup.cleanUp()
-        zcml.load_site(force=True)
-
-        self.saved = sys.path[:]
-        sys.path.append(ZopeTestCase.__path__[0])
-
-    def afterClear(self):
-        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:
-        return TestSuite((
-            ZopeDocTestSuite(test_class=TestClass),
-        ))
-    else:
-        return TestSuite()
-

Added: Zope/trunk/src/Testing/ZopeTestCase/zopedoctest/testPackageAsProduct.py
===================================================================
--- Zope/trunk/src/Testing/ZopeTestCase/zopedoctest/testPackageAsProduct.py     
                        (rev 0)
+++ Zope/trunk/src/Testing/ZopeTestCase/zopedoctest/testPackageAsProduct.py     
2010-06-27 14:07:11 UTC (rev 113940)
@@ -0,0 +1,92 @@
+##############################################################################
+#
+# Copyright (c) 2005 Zope Foundation and Contributors.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Tests for installPackage
+
+$Id$
+"""
+
+import sys
+from unittest import TestSuite
+
+from Testing import ZopeTestCase
+from Testing.ZopeTestCase import ZopeLite
+from Testing.ZopeTestCase import ZopeDocTestSuite
+from Zope2.App import zcml
+from zope.testing import cleanup
+
+
+def testInstallPackage():
+    """
+    Test if installPackage works.
+
+      >>> from Testing import ZopeTestCase
+      >>> from Zope2.App import zcml
+
+    Register testpackage
+
+      >>> ZopeTestCase.hasPackage('testpackage')
+      False
+
+      >>> config = '''
+      ... <configure
+      ...     xmlns:five="http://namespaces.zope.org/five";>
+      ...   <five:registerPackage
+      ...     package="testpackage"
+      ...     initialize="testpackage.initialize"
+      ...     />
+      ... </configure>'''
+      >>> zcml.load_string(config)
+
+    The package is registered now
+
+      >>> ZopeTestCase.hasPackage('testpackage')
+      True
+
+    Install it
+
+      >>> ZopeTestCase.installPackage('testpackage', quiet=True)
+      testpackage.initialize called
+
+    hasPackage still returns True
+
+      >>> ZopeTestCase.hasPackage('testpackage')
+      True
+
+    A package is only installed once, subsequent calls to installPackage
+    are ignored:
+
+      >>> ZopeTestCase.installPackage('testpackage', quiet=True)
+    """
+
+
+class TestClass(ZopeTestCase.FunctionalTestCase):
+
+    def afterSetUp(self):
+        cleanup.cleanUp()
+        zcml.load_site(force=True)
+
+        self.saved = sys.path[:]
+        sys.path.append(ZopeTestCase.__path__[0])
+
+    def afterClear(self):
+        cleanup.cleanUp()
+        sys.path[:] = self.saved
+
+
+def test_suite():
+    if ZopeLite.active:
+        return TestSuite((
+            ZopeDocTestSuite(test_class=TestClass),
+        ))
+    else:
+        return TestSuite()

_______________________________________________
Zope-Checkins maillist  -  Zope-Checkins@zope.org
https://mail.zope.org/mailman/listinfo/zope-checkins

Reply via email to