[Checkins] SVN: CMF/trunk/C - added registerDirectory ZCML directive
Yvo Schubbe
y.2007- at wcm-solutions.de
Tue Feb 27 08:13:45 EST 2007
Log message for revision 72873:
- added registerDirectory ZCML directive
- removed registration of CMFDefault/help
Changed:
U CMF/trunk/CHANGES.txt
U CMF/trunk/CMFActionIcons/__init__.py
U CMF/trunk/CMFActionIcons/configure.zcml
U CMF/trunk/CMFCalendar/__init__.py
U CMF/trunk/CMFCalendar/configure.zcml
U CMF/trunk/CMFCore/meta.zcml
U CMF/trunk/CMFCore/testing.zcml
A CMF/trunk/CMFCore/tests/test_zcml.py
A CMF/trunk/CMFCore/zcml.py
U CMF/trunk/CMFDefault/__init__.py
U CMF/trunk/CMFDefault/configure.zcml
A CMF/trunk/CMFDefault/directories.zcml
U CMF/trunk/CMFTopic/__init__.py
U CMF/trunk/CMFTopic/configure.zcml
-=-
Modified: CMF/trunk/CHANGES.txt
===================================================================
--- CMF/trunk/CHANGES.txt 2007-02-27 13:03:29 UTC (rev 72872)
+++ CMF/trunk/CHANGES.txt 2007-02-27 13:13:44 UTC (rev 72873)
@@ -2,6 +2,10 @@
New Features
+ - DirectoryView: Added 'registerDirectory' ZCML directive.
+ Using the old registerDirectory method in __init__.py is now deprecated.
+ See zcml.IRegisterDirectoryDirective for details.
+
- DirectoryView: Added support for non-product packages.
This introduces new registry keys. Old registry keys stored in
persistent DirectoryView objects are updated on the fly.
Modified: CMF/trunk/CMFActionIcons/__init__.py
===================================================================
--- CMF/trunk/CMFActionIcons/__init__.py 2007-02-27 13:03:29 UTC (rev 72872)
+++ CMF/trunk/CMFActionIcons/__init__.py 2007-02-27 13:13:44 UTC (rev 72873)
@@ -1,14 +1,14 @@
##############################################################################
#
# Copyright (c) 2003 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.
-#
+#
##############################################################################
""" Product: CMFActionIcons
@@ -17,14 +17,10 @@
$Id$
"""
-from Products.CMFCore.DirectoryView import registerDirectory
from Products.CMFCore.utils import ToolInit
import ActionIconsTool
-
-registerDirectory('skins', globals())
-
def initialize(context):
ToolInit( meta_type='CMF Action Icons Tool'
Modified: CMF/trunk/CMFActionIcons/configure.zcml
===================================================================
--- CMF/trunk/CMFActionIcons/configure.zcml 2007-02-27 13:03:29 UTC (rev 72872)
+++ CMF/trunk/CMFActionIcons/configure.zcml 2007-02-27 13:13:44 UTC (rev 72873)
@@ -1,8 +1,13 @@
<configure
xmlns="http://namespaces.zope.org/zope"
+ xmlns:cmf="http://namespaces.zope.org/cmf"
xmlns:genericsetup="http://namespaces.zope.org/genericsetup"
i18n_domain="cmf_default">
+ <!-- directories -->
+
+ <cmf:registerDirectory name="actionicons"/>
+
<!-- profiles -->
<genericsetup:registerProfile
Modified: CMF/trunk/CMFCalendar/__init__.py
===================================================================
--- CMF/trunk/CMFCalendar/__init__.py 2007-02-27 13:03:29 UTC (rev 72872)
+++ CMF/trunk/CMFCalendar/__init__.py 2007-02-27 13:13:44 UTC (rev 72873)
@@ -17,7 +17,6 @@
from Products.CMFCore.utils import ContentInit
from Products.CMFCore.utils import ToolInit
-from Products.CMFCore.DirectoryView import registerDirectory
import Event
import CalendarTool
@@ -27,9 +26,6 @@
# Make sure security is initialized
import utils
-# Make the skins available as DirectoryViews
-registerDirectory('skins', globals())
-
def initialize(context):
ToolInit( 'CMF Calendar Tool'
Modified: CMF/trunk/CMFCalendar/configure.zcml
===================================================================
--- CMF/trunk/CMFCalendar/configure.zcml 2007-02-27 13:03:29 UTC (rev 72872)
+++ CMF/trunk/CMFCalendar/configure.zcml 2007-02-27 13:13:44 UTC (rev 72873)
@@ -1,5 +1,6 @@
<configure
xmlns="http://namespaces.zope.org/zope"
+ xmlns:cmf="http://namespaces.zope.org/cmf"
xmlns:five="http://namespaces.zope.org/five"
xmlns:genericsetup="http://namespaces.zope.org/genericsetup"
i18n_domain="cmf_calendar">
@@ -22,6 +23,10 @@
name="cmf.calendar.event"
/>
+ <!-- directories -->
+
+ <cmf:registerDirectory name="zpt_calendar"/>
+
<!-- profiles -->
<genericsetup:registerProfile
Modified: CMF/trunk/CMFCore/meta.zcml
===================================================================
--- CMF/trunk/CMFCore/meta.zcml 2007-02-27 13:03:29 UTC (rev 72872)
+++ CMF/trunk/CMFCore/meta.zcml 2007-02-27 13:13:44 UTC (rev 72873)
@@ -1,5 +1,14 @@
-<configure xmlns="http://namespaces.zope.org/zope">
+<configure
+ xmlns="http://namespaces.zope.org/zope"
+ xmlns:meta="http://namespaces.zope.org/meta">
<include file="browser/meta.zcml"/>
+ <meta:directive
+ name="registerDirectory"
+ namespace="http://namespaces.zope.org/cmf"
+ schema=".zcml.IRegisterDirectoryDirective"
+ handler=".zcml.registerDirectory"
+ />
+
</configure>
Modified: CMF/trunk/CMFCore/testing.zcml
===================================================================
--- CMF/trunk/CMFCore/testing.zcml 2007-02-27 13:03:29 UTC (rev 72872)
+++ CMF/trunk/CMFCore/testing.zcml 2007-02-27 13:13:44 UTC (rev 72873)
@@ -12,6 +12,11 @@
file="meta.zcml"
/>
+ <include
+ package="Products.CMFCore"
+ file="meta.zcml"
+ />
+
<include package="Products.Five"/>
<include package="Products.GenericSetup"/>
Added: CMF/trunk/CMFCore/tests/test_zcml.py
===================================================================
--- CMF/trunk/CMFCore/tests/test_zcml.py 2007-02-27 13:03:29 UTC (rev 72872)
+++ CMF/trunk/CMFCore/tests/test_zcml.py 2007-02-27 13:13:44 UTC (rev 72873)
@@ -0,0 +1,73 @@
+##############################################################################
+#
+# Copyright (c) 2007 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_registerDirectory():
+ """
+ Use the cmf:registerDirectory directive::
+
+ >>> import Products.CMFCore
+ >>> from Products.Five import zcml
+ >>> configure_zcml = '''
+ ... <configure xmlns:cmf="http://namespaces.zope.org/cmf">
+ ... <cmf:registerDirectory
+ ... name="fake_skin"
+ ... directory="tests/fake_skins/fake_skin"
+ ... recursive="True"
+ ... ignore="foo bar"
+ ... />
+ ... </configure>'''
+ >>> zcml.load_config('meta.zcml', Products.CMFCore)
+ >>> zcml.load_string(configure_zcml)
+
+ Make sure the directory is registered correctly::
+
+ >>> from Products.CMFCore.DirectoryView import _dirreg
+ >>> reg_keys = ('Products.CMFCore:tests/fake_skins/fake_skin',
+ ... 'Products.CMFCore:tests/fake_skins/fake_skin/test_directory')
+ >>> reg_keys[0] in _dirreg._directories
+ True
+ >>> reg_keys[1] in _dirreg._directories
+ True
+ >>> info = _dirreg._directories[reg_keys[0]]
+ >>> info._reg_key == reg_keys[0]
+ True
+ >>> info.ignore
+ ('.', '..', 'foo', 'bar')
+
+ Clean up and make sure the cleanup works::
+
+ >>> from zope.testing.cleanup import cleanUp
+ >>> cleanUp()
+ >>> reg_keys[0] in _dirreg._directories
+ False
+ >>> reg_keys[1] in _dirreg._directories
+ False
+ """
+
+
+def test_suite():
+ return unittest.TestSuite((
+ doctest.DocTestSuite(),
+ ))
+
+if __name__ == '__main__':
+ unittest.main(defaultTest='test_suite')
Property changes on: CMF/trunk/CMFCore/tests/test_zcml.py
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: CMF/trunk/CMFCore/zcml.py
===================================================================
--- CMF/trunk/CMFCore/zcml.py 2007-02-27 13:03:29 UTC (rev 72872)
+++ CMF/trunk/CMFCore/zcml.py 2007-02-27 13:13:44 UTC (rev 72873)
@@ -0,0 +1,94 @@
+##############################################################################
+#
+# Copyright (c) 2007 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.
+#
+##############################################################################
+"""CMFCore ZCML directives.
+
+$Id$
+"""
+
+from os import path
+
+from zope.configuration.fields import Bool
+from zope.configuration.fields import Path
+from zope.configuration.fields import PythonIdentifier
+from zope.configuration.fields import Tokens
+from zope.interface import Interface
+from zope.schema import ASCIILine
+
+from DirectoryView import _dirreg
+from DirectoryView import _generateKey
+from DirectoryView import ignore
+
+
+class IRegisterDirectoryDirective(Interface):
+
+ """Register directories with the global registry.
+ """
+
+ name = PythonIdentifier(
+ title=u'Name',
+ description=u'Name of the directory.',
+ required=True)
+
+ directory = Path(
+ title=u'Path',
+ description=u'Path relative to the package. If not specified, '
+ u"'skins/<name>' is used.",
+ required=False)
+
+ recursive = Bool(
+ title=u'Recursive?',
+ description=u'False by default. If true, register all subdirectories '
+ u'as well.',
+ required=False)
+
+ ignore = Tokens(
+ title=u'Ignore',
+ description=u'Files and subdirectories that should be ignored. If '
+ u"not specified, 'CVS' and '.svn' are ignored.",
+ value_type=ASCIILine(),
+ required=False)
+
+
+_directory_regs = []
+def registerDirectory(_context, name, directory=None, recursive=False,
+ ignore=ignore):
+ """ Add a new directory to the registry.
+ """
+ if directory is None:
+ subdir = 'skins/%s' % str(name)
+ filepath = path.join(_context.package.__path__[0], 'skins', str(name))
+ else:
+ subdir = str(directory[len(_context.package.__path__[0])+1:])
+ filepath = str(directory)
+
+ reg_key = _generateKey(_context.package.__name__, subdir)
+ _directory_regs.append(reg_key)
+
+ _context.action(
+ discriminator = ('registerDirectory', reg_key),
+ callable = _dirreg.registerDirectoryByKey,
+ args = (filepath, reg_key, int(recursive), ignore)
+ )
+
+
+def cleanUp():
+ global _directory_regs
+ for reg_key in _directory_regs:
+ for key in _dirreg._directories.keys():
+ if key.startswith(reg_key):
+ del _dirreg._directories[key]
+ _directory_regs = []
+
+from zope.testing.cleanup import addCleanUp
+addCleanUp(cleanUp)
+del addCleanUp
Property changes on: CMF/trunk/CMFCore/zcml.py
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Modified: CMF/trunk/CMFDefault/__init__.py
===================================================================
--- CMF/trunk/CMFDefault/__init__.py 2007-02-27 13:03:29 UTC (rev 72872)
+++ CMF/trunk/CMFDefault/__init__.py 2007-02-27 13:13:44 UTC (rev 72873)
@@ -15,7 +15,6 @@
$Id$
"""
-from Products.CMFCore.DirectoryView import registerDirectory
from Products.CMFCore.utils import ToolInit
from Products.CMFCore.utils import ContentInit
from Products.CMFCore.utils import registerIcon
@@ -61,10 +60,6 @@
, SyndicationTool.SyndicationTool
)
-# Make the skins available as DirectoryViews.
-registerDirectory('skins', globals())
-registerDirectory('help', globals())
-
def initialize(context):
ToolInit( 'CMF Default Tool'
Modified: CMF/trunk/CMFDefault/configure.zcml
===================================================================
--- CMF/trunk/CMFDefault/configure.zcml 2007-02-27 13:03:29 UTC (rev 72872)
+++ CMF/trunk/CMFDefault/configure.zcml 2007-02-27 13:13:44 UTC (rev 72873)
@@ -11,4 +11,6 @@
<include file="profiles.zcml"/>
+ <include file="directories.zcml"/>
+
</configure>
Added: CMF/trunk/CMFDefault/directories.zcml
===================================================================
--- CMF/trunk/CMFDefault/directories.zcml 2007-02-27 13:03:29 UTC (rev 72872)
+++ CMF/trunk/CMFDefault/directories.zcml 2007-02-27 13:13:44 UTC (rev 72873)
@@ -0,0 +1,13 @@
+<configure
+ xmlns="http://namespaces.zope.org/zope"
+ xmlns:cmf="http://namespaces.zope.org/cmf">
+
+ <cmf:registerDirectory name="Images"/>
+
+ <cmf:registerDirectory name="zpt_content"/>
+
+ <cmf:registerDirectory name="zpt_control"/>
+
+ <cmf:registerDirectory name="zpt_generic"/>
+
+</configure>
Property changes on: CMF/trunk/CMFDefault/directories.zcml
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: CMF/trunk/CMFTopic/__init__.py
===================================================================
--- CMF/trunk/CMFTopic/__init__.py 2007-02-27 13:03:29 UTC (rev 72872)
+++ CMF/trunk/CMFTopic/__init__.py 2007-02-27 13:13:44 UTC (rev 72873)
@@ -16,7 +16,6 @@
"""
from Products.CMFCore.utils import ContentInit
-from Products.CMFCore.DirectoryView import registerDirectory
import Topic
from permissions import AddTopics
@@ -29,9 +28,6 @@
import SimpleStringCriterion
import SortCriterion
-# Make the skins available as DirectoryViews
-registerDirectory( 'skins', globals() )
-
def initialize(context):
context.registerHelpTitle( 'CMF Topic Help' )
Modified: CMF/trunk/CMFTopic/configure.zcml
===================================================================
--- CMF/trunk/CMFTopic/configure.zcml 2007-02-27 13:03:29 UTC (rev 72872)
+++ CMF/trunk/CMFTopic/configure.zcml 2007-02-27 13:13:44 UTC (rev 72873)
@@ -1,5 +1,6 @@
<configure
xmlns="http://namespaces.zope.org/zope"
+ xmlns:cmf="http://namespaces.zope.org/cmf"
xmlns:five="http://namespaces.zope.org/five"
xmlns:genericsetup="http://namespaces.zope.org/genericsetup"
i18n_domain="cmf_default">
@@ -22,6 +23,10 @@
name="cmf.topic"
/>
+ <!-- directories -->
+
+ <cmf:registerDirectory name="zpt_topic"/>
+
<!-- profiles -->
<genericsetup:registerProfile
More information about the Checkins
mailing list