[Checkins] SVN: GenericSetup/trunk/ - added 'registerProfile' ZCML directive

Yvo Schubbe y.2006_ at wcm-solutions.de
Wed Jun 7 12:24:13 EDT 2006


Log message for revision 68512:
  - added 'registerProfile' ZCML directive
  

Changed:
  U   GenericSetup/trunk/CHANGES.txt
  U   GenericSetup/trunk/doc/profiles.txt
  A   GenericSetup/trunk/meta.zcml
  A   GenericSetup/trunk/tests/test_zcml.py
  U   GenericSetup/trunk/tool.py
  A   GenericSetup/trunk/zcml.py

-=-
Modified: GenericSetup/trunk/CHANGES.txt
===================================================================
--- GenericSetup/trunk/CHANGES.txt	2006-06-07 14:30:13 UTC (rev 68511)
+++ GenericSetup/trunk/CHANGES.txt	2006-06-07 16:24:12 UTC (rev 68512)
@@ -2,6 +2,14 @@
 
   GenericSetup 1.2 (unreleased)
 
+    - ProfileRegistry: Added 'registerProfile' ZCML directive.
+      Using the old registerProfile method in initialize() is now deprecated.
+      See doc/profiles.txt for details.
+
+    - ProfileRegistry: 'product' should now be the module name.
+      For backwards compatibility 'product' is still first looked up in
+      Products before searching the default module search path.
+
     - ZCTextIndex handler: Fixed 'indexed_attr' import.
       (http://www.zope.org/Collectors/CMF/436)
 

Modified: GenericSetup/trunk/doc/profiles.txt
===================================================================
--- GenericSetup/trunk/doc/profiles.txt	2006-06-07 14:30:13 UTC (rev 68511)
+++ GenericSetup/trunk/doc/profiles.txt	2006-06-07 16:24:12 UTC (rev 68512)
@@ -13,24 +13,36 @@
   Registering Profiles
 
     By convention profiles are stored in a 'profiles' directory within a Zope
-    product. They have to be registered explicitly with a registerProfile call
-    in the __init__.py of the product.
+    product. They have to be registered explicitly using registerProfile.
 
-    Here is example code for MyProduct that extends BaseProduct::
+    Here is example ZCML for MyProduct that extends BaseProduct::
 
+      <genericsetup:registerProfile
+          name="install"
+          title="Install MyProduct Extension"
+          description="Adds local settings necessary for MyProduct."
+          provides="Products.GenericSetup.interfaces.EXTENSION"
+          for="Products.BaseProduct.interfaces.IBaseRoot"
+          />
+
+    See zcml.IRegisterProfileDirective for further details.
+
+    Alternatively the registerProfile method can be called. Using this for
+    product initialization is deprecated. Here is the code for the same
+    example::
+
       from Products.BaseProduct.interfaces import IBaseRoot
       from Products.GenericSetup import EXTENSION
       from Products.GenericSetup import profile_registry
 
-      def initialize(context):
-          profile_registry.registerProfile(
-                  name='install',
-                  title='Install MyProduct Extension',
-                  description='Adds local settings necessary for MyProduct.',
-                  path='profiles/install',
-                  product='MyProduct',
-                  profile_type=EXTENSION,
-                  for_=IBaseRoot)
+      profile_registry.registerProfile(
+              name='install',
+              title='Install MyProduct Extension',
+              description='Adds local settings necessary for MyProduct.',
+              path='profiles/install',
+              product='Products.MyProduct',
+              profile_type=EXTENSION,
+              for_=IBaseRoot)
 
     See IProfileRegistry.registerProfile for further details.
 

Added: GenericSetup/trunk/meta.zcml
===================================================================
--- GenericSetup/trunk/meta.zcml	2006-06-07 14:30:13 UTC (rev 68511)
+++ GenericSetup/trunk/meta.zcml	2006-06-07 16:24:12 UTC (rev 68512)
@@ -0,0 +1,12 @@
+<configure
+    xmlns="http://namespaces.zope.org/zope"
+    xmlns:meta="http://namespaces.zope.org/meta">
+
+  <meta:directive
+      name="registerProfile"
+      namespace="http://namespaces.zope.org/genericsetup"
+      schema=".zcml.IRegisterProfileDirective"
+      handler=".zcml.registerProfile"
+      />
+
+</configure>


Property changes on: GenericSetup/trunk/meta.zcml
___________________________________________________________________
Name: svn:eol-style
   + native

Added: GenericSetup/trunk/tests/test_zcml.py
===================================================================
--- GenericSetup/trunk/tests/test_zcml.py	2006-06-07 14:30:13 UTC (rev 68511)
+++ GenericSetup/trunk/tests/test_zcml.py	2006-06-07 16:24:12 UTC (rev 68512)
@@ -0,0 +1,84 @@
+##############################################################################
+#
+# Copyright (c) 2006 Zope Corporation and Contributors. All Rights Reserved.
+#
+# 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.
+#
+##############################################################################
+"""Unit tests for zcml module.
+
+$Id$
+"""
+
+import unittest
+import Testing
+from zope.testing import doctest
+
+
+def test_registerProfile():
+    """
+    Use the genericsetup:registerProfile directive::
+
+      >>> import Products.GenericSetup
+      >>> from Products.Five import zcml
+      >>> configure_zcml = '''
+      ... <configure
+      ...     xmlns:genericsetup="http://namespaces.zope.org/genericsetup"
+      ...     i18n_domain="foo">
+      ...   <genericsetup:registerProfile
+      ...       name="default"
+      ...       title="Install Foo Extension"
+      ...       description="Adds foo support."
+      ...       provides="Products.GenericSetup.interfaces.EXTENSION"
+      ...       />
+      ... </configure>'''
+      >>> zcml.load_config('meta.zcml', Products.GenericSetup)
+      >>> zcml.load_string(configure_zcml)
+
+    Make sure the profile is registered correctly::
+
+      >>> from Products.GenericSetup.registry import _profile_registry
+      >>> profile_id = 'Products.GenericSetup:default'
+      >>> profile_id in _profile_registry._profile_ids
+      True
+      >>> info = _profile_registry._profile_info[profile_id]
+      >>> info['id']
+      u'Products.GenericSetup:default'
+      >>> info['title']
+      u'Install Foo Extension'
+      >>> info['description']
+      u'Adds foo support.'
+      >>> info['path']
+      u'profiles/default'
+      >>> info['product']
+      'Products.GenericSetup'
+      >>> from Products.GenericSetup.interfaces import EXTENSION
+      >>> info['type'] is EXTENSION
+      True
+      >>> info['for'] is None
+      True
+
+    Clean up and make sure the cleanup works::
+
+      >>> # BBB: in Zope 2.8 we can't import cleanUp
+      ... from zope.testing.cleanup import CleanUp
+      >>> CleanUp().cleanUp()
+      >>> profile_id in _profile_registry._profile_ids
+      False
+      >>> profile_id in _profile_registry._profile_info
+      False
+    """
+
+
+def test_suite():
+    return unittest.TestSuite((
+        doctest.DocTestSuite(),
+        ))
+
+if __name__ == '__main__':
+    unittest.main(defaultTest='test_suite')


Property changes on: GenericSetup/trunk/tests/test_zcml.py
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Modified: GenericSetup/trunk/tool.py
===================================================================
--- GenericSetup/trunk/tool.py	2006-06-07 14:30:13 UTC (rev 68511)
+++ GenericSetup/trunk/tool.py	2006-06-07 16:24:12 UTC (rev 68512)
@@ -602,10 +602,16 @@
         """ Return the absolute path of the product's directory.
         """
         try:
+            # BBB: for GenericSetup 1.1 style product names
             product = __import__('Products.%s' % product_name
                                 , globals(), {}, ['initialize'])
         except ImportError:
-            raise ValueError, 'Not a valid product name: %s' % product_name
+            try:
+                product = __import__(product_name
+                                    , globals(), {}, ['initialize'])
+            except ImportError:
+                raise ValueError('Not a valid product name: %s'
+                                 % product_name)
 
         return product.__path__[0]
 

Added: GenericSetup/trunk/zcml.py
===================================================================
--- GenericSetup/trunk/zcml.py	2006-06-07 14:30:13 UTC (rev 68511)
+++ GenericSetup/trunk/zcml.py	2006-06-07 16:24:12 UTC (rev 68512)
@@ -0,0 +1,93 @@
+##############################################################################
+#
+# Copyright (c) 2006 Zope Corporation and Contributors. All Rights Reserved.
+#
+# 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.
+#
+##############################################################################
+"""GenericSetup ZCML directives.
+
+$Id$
+"""
+
+from zope.configuration.fields import GlobalObject
+from zope.configuration.fields import MessageID
+from zope.configuration.fields import Path
+from zope.configuration.fields import PythonIdentifier
+from zope.interface import Interface
+
+from interfaces import BASE
+from registry import _profile_registry
+
+
+class IRegisterProfileDirective(Interface):
+
+    """Register profiles with the global registry.
+    """
+
+    name = PythonIdentifier(
+        title=u'Name',
+        description=u'',
+        required=True)
+
+    title = MessageID(
+        title=u'Title',
+        description=u'',
+        required=True)
+
+    description = MessageID(
+        title=u'Description',
+        description=u'',
+        required=True)
+
+    directory = Path(
+        title=u'Path',
+        description=u"If not specified 'profiles/<name>' is used.",
+        required=False)
+
+    provides = GlobalObject(
+        title=u'Type',
+        description=u"If not specified 'BASE' is used.",
+        default=BASE,
+        required=False)
+
+    for_ = GlobalObject(
+        title=u'Site Interface',
+        description=u'If not specified the profile is always available.',
+        default=None,
+        required=False)
+
+
+_profile_regs = []
+def registerProfile(_context, name, title, description, directory=None,
+                    provides=BASE, for_=None):
+    """ Add a new profile to the registry.
+    """
+    product = _context.package.__name__
+    if directory is None:
+        directory = 'profiles/%s' % name
+
+    _profile_regs.append('%s:%s' % (product, name))
+
+    _context.action(
+        discriminator = ('registerProfile', product, name),
+        callable = _profile_registry.registerProfile,
+        args = (name, title, description, directory, product, provides, for_)
+        )
+
+
+def cleanUp():
+    global _profile_regs
+    for profile_id in _profile_regs:
+        del _profile_registry._profile_info[profile_id]
+        _profile_registry._profile_ids.remove(profile_id)
+    _profile_regs = []
+
+from zope.testing.cleanup import addCleanUp
+addCleanUp(cleanUp)
+del addCleanUp


Property changes on: GenericSetup/trunk/zcml.py
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native



More information about the Checkins mailing list