[CMF-checkins] SVN: CMF/branches/1.5/C CMFActionIcons: added support for exporting / importing action icons tool configuration

Tres Seaver tseaver at palladion.com
Sun Oct 16 14:42:09 EDT 2005


Log message for revision 39478:
  CMFActionIcons:  added support for exporting / importing action icons tool configuration
  
  (via GenericSetup).
  
  

Changed:
  U   CMF/branches/1.5/CHANGES.txt
  U   CMF/branches/1.5/CMFActionIcons/__init__.py
  A   CMF/branches/1.5/CMFActionIcons/exportimport.py
  A   CMF/branches/1.5/CMFActionIcons/profiles/
  A   CMF/branches/1.5/CMFActionIcons/profiles/actionicons/
  A   CMF/branches/1.5/CMFActionIcons/profiles/actionicons/actionicons.xml
  A   CMF/branches/1.5/CMFActionIcons/profiles/actionicons/export_steps.xml
  A   CMF/branches/1.5/CMFActionIcons/profiles/actionicons/import_steps.xml
  A   CMF/branches/1.5/CMFActionIcons/profiles/actionicons/toolset.xml
  A   CMF/branches/1.5/CMFActionIcons/tests/test_exportimport.py
  A   CMF/branches/1.5/CMFActionIcons/xml/
  A   CMF/branches/1.5/CMFActionIcons/xml/aitExport.xml

-=-
Modified: CMF/branches/1.5/CHANGES.txt
===================================================================
--- CMF/branches/1.5/CHANGES.txt	2005-10-16 18:38:14 UTC (rev 39477)
+++ CMF/branches/1.5/CHANGES.txt	2005-10-16 18:42:09 UTC (rev 39478)
@@ -16,6 +16,9 @@
 
   Features
 
+    - CMFActionIcons:  added support for exporting / importing
+      action icons tool configuration (via GenericSetup).
+
     - CMFSetup:  added support for configuring content type registry.
 
     - CMFSetup:  added support for configuring caching policy manager.

Modified: CMF/branches/1.5/CMFActionIcons/__init__.py
===================================================================
--- CMF/branches/1.5/CMFActionIcons/__init__.py	2005-10-16 18:38:14 UTC (rev 39477)
+++ CMF/branches/1.5/CMFActionIcons/__init__.py	2005-10-16 18:42:09 UTC (rev 39478)
@@ -18,8 +18,14 @@
 """
 from Products.CMFCore.DirectoryView import registerDirectory
 from Products.CMFCore.utils import ToolInit
+try:
+    from Products.CMFSetup import EXTENSION
+    from Products.CMFSetup import profile_registry
+    has_profile_registry = True
+except ImportError:
+    has_profile_registry = False
 
-from ActionIconsTool import ActionIconsTool
+import ActionIconsTool
 
 actionicons_globals = globals()
 
@@ -28,6 +34,14 @@
 def initialize( context ):
 
     ToolInit( meta_type='CMF Action Icons Tool'
-            , tools=( ActionIconsTool, )
+            , tools=( ActionIconsTool.ActionIconsTool, )
             , icon="tool.gif"
             ).initialize( context )
+
+    if has_profile_registry:
+        profile_registry.registerProfile('actionicons',
+                                         'CMFActionIcons',
+                                         'Adds action icon tool / settings.',
+                                         'profiles/actionicons',
+                                         'CMFActionIcons',
+                                         EXTENSION)

Added: CMF/branches/1.5/CMFActionIcons/exportimport.py
===================================================================
--- CMF/branches/1.5/CMFActionIcons/exportimport.py	2005-10-16 18:38:14 UTC (rev 39477)
+++ CMF/branches/1.5/CMFActionIcons/exportimport.py	2005-10-16 18:42:09 UTC (rev 39478)
@@ -0,0 +1,118 @@
+##############################################################################
+#
+# Copyright (c) 2005 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.
+#
+##############################################################################
+"""ActionIconsTool setup handlers.
+
+$Id$
+"""
+import os
+
+from AccessControl import ClassSecurityInfo
+from AccessControl.Permission import Permission
+from Globals import InitializeClass
+from Globals import package_home
+from Products.PageTemplates.PageTemplateFile import PageTemplateFile
+
+from Products.CMFCore.utils import getToolByName
+
+from Products.CMFSetup.utils import CONVERTER
+from Products.CMFSetup.utils import DEFAULT
+from Products.CMFSetup.utils import ExportConfiguratorBase
+from Products.CMFSetup.utils import ImportConfiguratorBase
+from Products.CMFSetup.utils import KEY
+
+from permissions import ManagePortal
+
+_pkgdir = package_home( globals() )
+_xmldir = os.path.join( _pkgdir, 'xml' )
+
+#
+#   Configurator entry points
+#
+_FILENAME = 'actionicons.xml'
+
+def importActionIconsTool(context):
+    """ Import cache policy maanger settings from an XML file.
+    """
+    site = context.getSite()
+    ait = getToolByName(site, 'portal_actionicons', None)
+    if ait is None:
+        return 'Action icons: No tool!'
+
+    body = context.readDataFile(_FILENAME)
+    if body is None:
+        return 'Action icons: Nothing to import.'
+
+    if context.shouldPurge():
+        ait.clearActionIcons()
+
+    # now act on the settings we've retrieved
+    configurator = ActionIconsToolImportConfigurator(site)
+    ait_info = configurator.parseXML(body)
+
+    for action_icon in ait_info['action_icons']:
+        ait.addActionIcon(**action_icon)
+
+    return 'Action icons settings imported.'
+
+def exportActionIconsTool(context):
+    """ Export caching policy manager settings as an XML file.
+    """
+    site = context.getSite()
+    mhc = ActionIconsToolExportConfigurator( site ).__of__( site )
+    text = mhc.generateXML()
+
+    context.writeDataFile( _FILENAME, text, 'text/xml' )
+
+    return 'Action icons tool settings exported.'
+
+class ActionIconsToolExportConfigurator(ExportConfiguratorBase):
+    """ Synthesize XML description of cc properties.
+    """
+    security = ClassSecurityInfo()
+
+    security.declareProtected( ManagePortal, 'listActionIconInfo' )
+    def listActionIconInfo(self):
+        """ Return a list of mappings describing the action icons.
+        """
+        ait = getToolByName(self._site, 'portal_actionicons')
+        for action_icon in ait.listActionIcons():
+            yield {'category': action_icon.getCategory(),
+                   'action_id': action_icon.getActionId(),
+                   'title': action_icon.getTitle(),
+                   'priority': action_icon.getPriority(),
+                   'icon_expr': action_icon.getExpression(),
+                  }
+
+    security.declarePrivate('_getExportTemplate')
+    def _getExportTemplate(self):
+
+        return PageTemplateFile('aitExport.xml', _xmldir)
+
+InitializeClass(ActionIconsToolExportConfigurator)
+
+class ActionIconsToolImportConfigurator(ImportConfiguratorBase):
+
+    def _getImportMapping(self):
+        return {
+          'action-icons':
+             { 'action-icon': {KEY: 'action_icons', DEFAULT: ()} },
+          'action-icon':
+             { 'category':      {},
+               'action_id':     {},
+               'title':         {},
+               'icon_expr':     {},
+               'priority':      {CONVERTER: self._convertToInteger},
+             },
+          }
+
+InitializeClass(ActionIconsToolImportConfigurator)


Property changes on: CMF/branches/1.5/CMFActionIcons/exportimport.py
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: CMF/branches/1.5/CMFActionIcons/profiles/actionicons/actionicons.xml
===================================================================
--- CMF/branches/1.5/CMFActionIcons/profiles/actionicons/actionicons.xml	2005-10-16 18:38:14 UTC (rev 39477)
+++ CMF/branches/1.5/CMFActionIcons/profiles/actionicons/actionicons.xml	2005-10-16 18:42:09 UTC (rev 39478)
@@ -0,0 +1,39 @@
+<?xml version="1.0"?>
+<action-icons>
+ <action-icon category="folder" action_id="folderContents"
+              title="Folder Contents" priority="0"
+              icon_expr="folder_icon.png"/>
+ <action-icon category="object" action_id="folderContents"
+              title="Folder Contents" priority="0"
+              icon_expr="folder_icon.png"/>
+ <action-icon category="object" action_id="view"
+              title="View" priority="1"
+              icon_expr="preview_icon.png"/>
+ <action-icon category="object" action_id="edit"
+              title="Edit" priority="2"
+              icon_expr="edit_icon.png"/>
+ <action-icon category="object" action_id="metadata"
+              title="Metadata" priority="3"
+              icon_expr="metadata_icon.png"/>
+ <action-icon category="object" action_id="localroles"
+              title="Local Roles" priority="3"
+              icon_expr="user_icon.png"/>
+ <action-icon category="global" action_id="undo"
+              title="Undo" priority="6"
+              icon_expr="user_icon.png"/>
+ <action-icon category="object" action_id="syndication"
+              title="Syndication" priority="4"
+              icon_expr="user_icon.png"/>
+ <action-icon category="workflow" action_id="submit"
+              title="Submit" priority="0"
+              icon_expr="submit_icon.png"/>
+ <action-icon category="workflow" action_id="reject"
+              title="Reject" priority="1"
+              icon_expr="reject_icon.png"/>
+ <action-icon category="workflow" action_id="retract"
+              title="Retract" priority="1"
+              icon_expr="retract_icon.png"/>
+ <action-icon category="workflow" action_id="approve"
+              title="Approve" priority="2"
+              icon_expr="approve_icon.png"/>
+</action-icons>


Property changes on: CMF/branches/1.5/CMFActionIcons/profiles/actionicons/actionicons.xml
___________________________________________________________________
Name: svn:eol-style
   + native

Added: CMF/branches/1.5/CMFActionIcons/profiles/actionicons/export_steps.xml
===================================================================
--- CMF/branches/1.5/CMFActionIcons/profiles/actionicons/export_steps.xml	2005-10-16 18:38:14 UTC (rev 39477)
+++ CMF/branches/1.5/CMFActionIcons/profiles/actionicons/export_steps.xml	2005-10-16 18:42:09 UTC (rev 39478)
@@ -0,0 +1,8 @@
+<?xml version="1.0"?>
+<export-steps>
+ <export-step id="action-icons"
+              handler="Products.CMFActionIcons.exportimport.exportActionIconsTool"
+              title="Action Icons">
+  Export action icon definitions
+ </export-step>
+</export-steps>


Property changes on: CMF/branches/1.5/CMFActionIcons/profiles/actionicons/export_steps.xml
___________________________________________________________________
Name: svn:eol-style
   + native

Added: CMF/branches/1.5/CMFActionIcons/profiles/actionicons/import_steps.xml
===================================================================
--- CMF/branches/1.5/CMFActionIcons/profiles/actionicons/import_steps.xml	2005-10-16 18:38:14 UTC (rev 39477)
+++ CMF/branches/1.5/CMFActionIcons/profiles/actionicons/import_steps.xml	2005-10-16 18:42:09 UTC (rev 39478)
@@ -0,0 +1,9 @@
+<?xml version="1.0"?>
+<import-steps>
+ <import-step id="action-icons" version="20051015-01"
+              handler="Products.CMFActionIcons.exportimport.importActionIconsTool"
+              title="Action Icons">
+  <dependency step="toolset"/>
+  Import action icon definitions
+ </import-step>
+</import-steps>


Property changes on: CMF/branches/1.5/CMFActionIcons/profiles/actionicons/import_steps.xml
___________________________________________________________________
Name: svn:eol-style
   + native

Added: CMF/branches/1.5/CMFActionIcons/profiles/actionicons/toolset.xml
===================================================================
--- CMF/branches/1.5/CMFActionIcons/profiles/actionicons/toolset.xml	2005-10-16 18:38:14 UTC (rev 39477)
+++ CMF/branches/1.5/CMFActionIcons/profiles/actionicons/toolset.xml	2005-10-16 18:42:09 UTC (rev 39478)
@@ -0,0 +1,5 @@
+<?xml version="1.0"?>
+<tool-setup>
+ <required tool_id="portal_actionicons"
+           class="Products.CMFActionIcons.ActionIconsTool.ActionIconsTool"/>
+</tool-setup>


Property changes on: CMF/branches/1.5/CMFActionIcons/profiles/actionicons/toolset.xml
___________________________________________________________________
Name: svn:eol-style
   + native

Added: CMF/branches/1.5/CMFActionIcons/tests/test_exportimport.py
===================================================================
--- CMF/branches/1.5/CMFActionIcons/tests/test_exportimport.py	2005-10-16 18:38:14 UTC (rev 39477)
+++ CMF/branches/1.5/CMFActionIcons/tests/test_exportimport.py	2005-10-16 18:42:09 UTC (rev 39478)
@@ -0,0 +1,191 @@
+##############################################################################
+#
+# Copyright (c) 2005 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.
+#
+##############################################################################
+"""ActionIconsTool setup handler unit tests.
+
+$Id$
+"""
+import unittest
+#import Testing
+
+
+from Products.CMFSetup.tests.common import BaseRegistryTests
+from Products.CMFSetup.tests.common import DummyExportContext
+from Products.CMFSetup.tests.common import DummyImportContext
+
+
+class _ActionIconsToolSetup(BaseRegistryTests):
+
+    CATEGORY = 'testing'
+    ACTION_ID = "test_action"
+    TITLE = "Action Title"
+    PRIORITY = 60
+    ICON_EXPR = 'test_icon'
+
+    _EMPTY_EXPORT = """\
+<?xml version="1.0"?>
+<action-icons>
+</action-icons>
+"""
+
+    _WITH_ICON_EXPORT = """\
+<?xml version="1.0"?>
+<action-icons>
+ <action-icon
+    category="%s"
+    action_id="%s"
+    title="%s"
+    priority="%d"
+    icon_expr="%s"
+    />
+</action-icons>
+""" % (CATEGORY,
+       ACTION_ID,
+       TITLE,
+       PRIORITY,
+       ICON_EXPR,
+      )
+
+    def _initSite(self, with_icon=False):
+        from OFS.Folder import Folder
+        from Products.CMFActionIcons.ActionIconsTool import ActionIconsTool
+
+        self.root.site = Folder(id='site')
+        site = self.root.site
+        tool = ActionIconsTool()
+        site._setObject( tool.getId(), tool )
+
+        if with_icon:
+            tool.addActionIcon( category=self.CATEGORY
+                              , action_id=self.ACTION_ID
+                              , title=self.TITLE
+                              , priority=self.PRIORITY
+                              , icon_expr=self.ICON_EXPR
+                              )
+        return site
+
+class ActionIconsToolExportConfiguratorTests(_ActionIconsToolSetup):
+
+    def _getTargetClass(self):
+        from Products.CMFActionIcons.exportimport \
+                import ActionIconsToolExportConfigurator
+
+        return ActionIconsToolExportConfigurator
+
+    def test_generateXML_empty(self):
+        site = self._initSite(with_icon=False)
+        configurator = self._makeOne(site).__of__(site)
+
+        self._compareDOM(configurator.generateXML(), self._EMPTY_EXPORT)
+
+    def test_generateXML_with_icon(self):
+        site = self._initSite(with_icon=True)
+        configurator = self._makeOne(site).__of__(site)
+
+        self._compareDOM(configurator.generateXML(), self._WITH_ICON_EXPORT)
+
+
+class ActionIconsToolImportConfiguratorTests(_ActionIconsToolSetup):
+
+    def _getTargetClass(self):
+        from Products.CMFActionIcons.exportimport \
+                import ActionIconsToolImportConfigurator
+
+        return ActionIconsToolImportConfigurator
+
+    def test_parseXML_empty(self):
+        site = self._initSite(with_icon=False)
+        configurator = self._makeOne(site)
+        ait_info = configurator.parseXML(self._EMPTY_EXPORT)
+
+        self.assertEqual(len(ait_info['action_icons']), 0)
+
+    def test_parseXML_with_icon(self):
+        site = self._initSite(with_icon=False)
+        configurator = self._makeOne(site)
+        ait_info = configurator.parseXML(self._WITH_ICON_EXPORT)
+
+        self.assertEqual(len(ait_info['action_icons']), 1)
+
+        info = ait_info['action_icons'][0]
+        self.assertEqual(info['category'], self.CATEGORY)
+        self.assertEqual(info['action_id'], self.ACTION_ID)
+        self.assertEqual(info['title'], self.TITLE)
+        self.assertEqual(info['priority'], self.PRIORITY)
+        self.assertEqual(info['icon_expr'], self.ICON_EXPR)
+
+class Test_exportActionIconsTool(_ActionIconsToolSetup):
+
+    def test_empty(self):
+        from Products.CMFActionIcons.exportimport \
+            import exportActionIconsTool
+
+        site = self._initSite(with_icon=False)
+        context = DummyExportContext(site)
+        exportActionIconsTool(context)
+
+        self.assertEqual(len(context._wrote), 1)
+        filename, text, content_type = context._wrote[0]
+        self.assertEqual(filename, 'actionicons.xml')
+        self._compareDOM(text, self._EMPTY_EXPORT)
+        self.assertEqual(content_type, 'text/xml')
+
+    def test_with_icon(self):
+        from Products.CMFActionIcons.exportimport \
+            import exportActionIconsTool
+
+        site = self._initSite(with_icon=True)
+        context = DummyExportContext(site)
+        exportActionIconsTool(context)
+
+        self.assertEqual(len(context._wrote), 1)
+        filename, text, content_type = context._wrote[0]
+        self.assertEqual(filename, 'actionicons.xml')
+        self._compareDOM(text, self._WITH_ICON_EXPORT)
+        self.assertEqual(content_type, 'text/xml')
+
+
+class Test_importActionIconsTool(_ActionIconsToolSetup):
+
+    def test_normal(self):
+        from Products.CMFActionIcons.exportimport \
+            import importActionIconsTool
+
+        site = self._initSite(with_icon=False)
+        ait = site.portal_actionicons
+        self.assertEqual(len(ait.listActionIcons()), 0)
+
+        context = DummyImportContext(site)
+        context._files['actionicons.xml'] = self._WITH_ICON_EXPORT
+        importActionIconsTool(context)
+
+        self.assertEqual(len(ait.listActionIcons()), 1)
+        action_icon = ait.listActionIcons()[0]
+
+        self.assertEqual(action_icon.getCategory(), self.CATEGORY)
+        self.assertEqual(action_icon.getActionId(), self.ACTION_ID)
+        self.assertEqual(action_icon.getTitle(), self.TITLE)
+        self.assertEqual(action_icon.getPriority(), self.PRIORITY)
+        self.assertEqual(action_icon.getExpression(), self.ICON_EXPR)
+
+
+def test_suite():
+    return unittest.TestSuite((
+        unittest.makeSuite(ActionIconsToolExportConfiguratorTests),
+        unittest.makeSuite(ActionIconsToolImportConfiguratorTests),
+        unittest.makeSuite(Test_exportActionIconsTool),
+        unittest.makeSuite(Test_importActionIconsTool),
+        ))
+
+if __name__ == '__main__':
+    unittest.main(defaultTest='test_suite')
+


Property changes on: CMF/branches/1.5/CMFActionIcons/tests/test_exportimport.py
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: CMF/branches/1.5/CMFActionIcons/xml/aitExport.xml
===================================================================
--- CMF/branches/1.5/CMFActionIcons/xml/aitExport.xml	2005-10-16 18:38:14 UTC (rev 39477)
+++ CMF/branches/1.5/CMFActionIcons/xml/aitExport.xml	2005-10-16 18:42:09 UTC (rev 39478)
@@ -0,0 +1,18 @@
+<?xml version="1.0"?>
+<action-icons xmlns:tal="http://xml.zope.org/namespaces/tal">
+ <action-icon
+    category="%s"
+    action_id="%s"
+    title="%s"
+    priority="%d"
+    icon_expr="%s"
+    tal:repeat="info context/listActionIconInfo"
+    tal:attributes="category info/category;
+                    action_id info/action_id;
+                    title info/title;
+                    priority info/priority;
+                    icon_expr info/icon_expr;
+                   "
+    />
+</action-icons>
+


Property changes on: CMF/branches/1.5/CMFActionIcons/xml/aitExport.xml
___________________________________________________________________
Name: svn:eol-style
   + native



More information about the CMF-checkins mailing list