[200] | 1 | #-*- mode: python; mode: fold -*- |
---|
[486] | 2 | # $Id: exportimport.py 486 2006-09-06 10:09:39Z joachim $ |
---|
[199] | 3 | """WAeUP Tool XML Adapter. |
---|
| 4 | |
---|
| 5 | An XML adapter tells the GenericSetup machinery howto im- / export persistent |
---|
| 6 | configuration that is relative to a specific CMF component such as our WAeUP |
---|
| 7 | Tool. |
---|
| 8 | |
---|
| 9 | GenericSetup uses the Zope3 interfaces and components machinery to find the |
---|
| 10 | right XML adapter for the right object. This is why we flagged our waeup tool |
---|
| 11 | with the `implements(IWAeUPTool)` class attribute and made an adapter |
---|
| 12 | association in the `configure.zcml` file. |
---|
| 13 | """ |
---|
[238] | 14 | import csv,re |
---|
[199] | 15 | |
---|
| 16 | # Zope3 component architecture |
---|
| 17 | from zope.component import adapts |
---|
| 18 | from zope.interface import implements |
---|
| 19 | |
---|
| 20 | # Standard GenericSetup base classes and functions |
---|
| 21 | from Products.GenericSetup.utils import exportObjects |
---|
| 22 | from Products.GenericSetup.utils import importObjects |
---|
| 23 | from Products.GenericSetup.utils import XMLAdapterBase |
---|
| 24 | from Products.GenericSetup.utils import PropertyManagerHelpers |
---|
| 25 | |
---|
| 26 | from Products.CMFCore.utils import getToolByName |
---|
| 27 | |
---|
| 28 | # GenericSetup multi adapts a class that implement IWAeUP and a particular |
---|
| 29 | # ISetupEnvironment to and IBody (piece of XML configuration). |
---|
| 30 | from Products.GenericSetup.interfaces import IBody |
---|
| 31 | from Products.GenericSetup.interfaces import ISetupEnviron |
---|
[274] | 32 | from Products.WAeUP_SRP.interfaces import IWAeUPTool |
---|
[238] | 33 | import Globals |
---|
| 34 | p_home = Globals.package_home(globals()) |
---|
| 35 | i_home = Globals.INSTANCE_HOME |
---|
[199] | 36 | |
---|
| 37 | TOOL = 'portal_waeup' |
---|
| 38 | NAME = 'waeup' |
---|
| 39 | |
---|
| 40 | def exportWAeUP(context): |
---|
| 41 | """Export our WAeUP tool configuration |
---|
| 42 | """ |
---|
| 43 | site = context.getSite() |
---|
[282] | 44 | tool = getattr(context,"campus",None) |
---|
[199] | 45 | if tool is None: |
---|
| 46 | logger = context.getLogger(NAME) |
---|
| 47 | logger.info("Nothing to export.") |
---|
| 48 | return |
---|
| 49 | exportObjects(tool, '', context) |
---|
| 50 | |
---|
| 51 | def importWAeUP(context): |
---|
| 52 | """Import WAeUP tool configuration |
---|
| 53 | """ |
---|
| 54 | site = context.getSite() |
---|
[350] | 55 | pm = site.portal_membership |
---|
[351] | 56 | pm.setLocalGroupRoles(site,['role:Authenticated',],'SectionReader') |
---|
[363] | 57 | |
---|
[404] | 58 | importObjects(site.portal_accommodation, '', context) |
---|
[363] | 59 | |
---|
| 60 | from Products.GenericSetup.ZCatalog.exportimport import ZCatalogXMLAdapter |
---|
| 61 | |
---|
| 62 | from interfaces import IWAeUPTable |
---|
| 63 | |
---|
| 64 | class WAeUPTableXMLAdapter(ZCatalogXMLAdapter): |
---|
| 65 | |
---|
| 66 | __used_for__ = IWAeUPTable |
---|
| 67 | |
---|
| 68 | _LOGGER_ID = 'waeup_table' |
---|
| 69 | |
---|
[404] | 70 | name = 'accommodation' |
---|
[363] | 71 | |
---|
[199] | 72 | # This the XMLAdapter itself. It encodes the im- / export logic that is specific |
---|
| 73 | # to our tool. `im- / exportObjects` functions will find it thanks to the zope |
---|
| 74 | # components machinery and the associations made in the configure.zcml file. |
---|
| 75 | |
---|
[282] | 76 | ##class WAeUPXMLAdapter(XMLAdapterBase, PropertyManagerHelpers): |
---|
| 77 | ## """XML importer and exporter for the WAeUP tool. |
---|
| 78 | ## |
---|
| 79 | ## Hence this XMLAdapter is really simple. To get more complete examples of |
---|
| 80 | ## what XMLAdapters are meant to do, please have a look at the |
---|
| 81 | ## CPSSkins.exportimport.py or CPSDirectory.exportimport.py files, for |
---|
| 82 | ## instance. |
---|
| 83 | ## """ |
---|
| 84 | ## |
---|
| 85 | ## adapts(IWAeUPTool, ISetupEnviron) |
---|
| 86 | ## implements(IBody) |
---|
| 87 | ## |
---|
| 88 | ## _LOGGER_ID = NAME |
---|
| 89 | ## name = NAME |
---|
| 90 | ## |
---|
| 91 | ## def _exportNode(self): |
---|
| 92 | ## """Export the object as a DOM node. |
---|
| 93 | ## """ |
---|
| 94 | ## node = self._getObjectNode('object') |
---|
| 95 | ## node.appendChild(self._extractProperties()) |
---|
| 96 | ## self._logger.info("WAeUP tool exported.") |
---|
| 97 | ## return node |
---|
| 98 | ## |
---|
| 99 | ## def _importNode(self, node): |
---|
| 100 | ## """Import the object from the DOM node. |
---|
| 101 | ## """ |
---|
| 102 | ## if self.environ.shouldPurge(): |
---|
| 103 | ## self._purgeProperties() |
---|
| 104 | ## self._initProperties(node) |
---|
| 105 | ## self._logger.info("WAeUP tool imported.") |
---|
| 106 | ## |
---|