source: WAeUP_SRP/trunk/exportimport.py @ 922

Last change on this file since 922 was 922, checked in by joachim, 20 years ago

give Authenticated the SectionReaderRole? in Academics

  • Property svn:keywords set to Id
File size: 4.8 KB
RevLine 
[200]1#-*- mode: python; mode: fold -*-
[486]2# $Id: exportimport.py 922 2006-11-22 12:39:53Z joachim $
[199]3"""WAeUP Tool XML Adapter.
4
5An XML adapter tells the GenericSetup machinery howto im- / export persistent
6configuration that is relative to a specific CMF component such as our WAeUP
7Tool.
8
9GenericSetup uses the Zope3 interfaces and components machinery to find the
10right XML adapter for the right object. This is why we flagged our waeup tool
11with the `implements(IWAeUPTool)` class attribute and made an adapter
12association in the `configure.zcml` file.
13"""
[238]14import csv,re
[199]15
16# Zope3 component architecture
[502]17from zope.app import zapi
[199]18from zope.component import adapts
19from zope.interface import implements
20
21# Standard GenericSetup base classes and functions
22from Products.GenericSetup.utils import exportObjects
23from Products.GenericSetup.utils import importObjects
24from Products.GenericSetup.utils import XMLAdapterBase
25from Products.GenericSetup.utils import PropertyManagerHelpers
26
27from Products.CMFCore.utils import getToolByName
28
29# GenericSetup multi adapts a class that implement IWAeUP and a particular
30# ISetupEnvironment to and IBody (piece of XML configuration).
31from Products.GenericSetup.interfaces import IBody
32from Products.GenericSetup.interfaces import ISetupEnviron
[274]33from Products.WAeUP_SRP.interfaces import IWAeUPTool
[238]34import Globals
35p_home = Globals.package_home(globals())
36i_home = Globals.INSTANCE_HOME
[199]37
38TOOL = 'portal_waeup'
39NAME = 'waeup'
40
[502]41def importWAeUPTable(obj, parent_path, context, name):
42    """ Import subobjects recursively.
43    """
44    importer = zapi.queryMultiAdapter((obj, context), IBody)
45   
46    path = '%s%s' % (parent_path, obj.getId().replace(' ', '_'))
47    __traceback_info__ = path
48    if importer:
49        path = '%s%s' % (parent_path, name)
50        filename = '%s%s' % (path, importer.suffix)
51        body = context.readDataFile(filename)
52        if body is not None:
53            importer.filename = filename # for error reporting
54            importer.body = body
55
56    if getattr(obj, 'objectValues', False):
57        for sub in obj.objectValues():
58            importObjects(sub, path+'/', context)
59
[199]60def exportWAeUP(context):
61    """Export our WAeUP tool configuration
62    """
63    site = context.getSite()
[282]64    tool = getattr(context,"campus",None)
[199]65    if tool is None:
66        logger = context.getLogger(NAME)
67        logger.info("Nothing to export.")
68        return
69    exportObjects(tool, '', context)
70
71def importWAeUP(context):
72    """Import WAeUP tool configuration
73    """
74    site = context.getSite()
[350]75    pm = site.portal_membership
[902]76    campus = site.portal_url.getPortalObject().campus
[905]77    pm.setLocalGroupRoles(campus.students,['group:ClearanceOfficers',
78                                           'role:Student',],'SectionReader')
[922]79    pm.setLocalGroupRoles(campus.academics,['Authenticated',
80                                           ],'SectionReader')
[502]81    importWAeUPTable(site.portal_accommodation, '', context,'accommodation')
82    importWAeUPTable(site.portal_pins, '', context,'pins')
[363]83   
[502]84from Products.CPSCore.exportimport.catalog import CatalogToolXMLAdapter
85#from Products.GenericSetup.ZCatalog.exportimport import ZCatalogXMLAdapter
[363]86
87from interfaces import IWAeUPTable
88
[502]89class WAeUPTableXMLAdapter(CatalogToolXMLAdapter):
90#class WAeUPTableXMLAdapter(ZCatalogXMLAdapter):
[363]91    __used_for__ = IWAeUPTable
92    _LOGGER_ID = 'waeup_table'
93
[502]94##    def _importNode(self, node):
95##        """Import the object from the DOM node.
96##        """
97##        if self.environ.shouldPurge():
98##            self._purgeProperties()
99##            self._purgeObjects()
100##            self._purgeIndexes()
101##            self._purgeColumns()
102##
103##        self._logger.info('Catalog imported.')
[199]104# This the XMLAdapter itself. It encodes the im- / export logic that is specific
105# to our tool. `im- / exportObjects` functions will find it thanks to the zope
106# components machinery and the associations made in the configure.zcml file.
107
[282]108##class WAeUPXMLAdapter(XMLAdapterBase, PropertyManagerHelpers):
109##    """XML importer and exporter for the WAeUP tool.
110##
111##    Hence this XMLAdapter is really simple. To get more complete examples of
112##    what XMLAdapters are meant to do, please have a look at the
113##    CPSSkins.exportimport.py or CPSDirectory.exportimport.py files, for
114##    instance.
115##    """
116##
117##    adapts(IWAeUPTool, ISetupEnviron)
118##    implements(IBody)
119##
120##    _LOGGER_ID = NAME
121##    name = NAME
122##
123##    def _exportNode(self):
124##        """Export the object as a DOM node.
125##        """
126##        node = self._getObjectNode('object')
127##        node.appendChild(self._extractProperties())
128##        self._logger.info("WAeUP tool exported.")
129##        return node
130##
131##    def _importNode(self, node):
132##        """Import the object from the DOM node.
133##        """
134##        if self.environ.shouldPurge():
135##            self._purgeProperties()
136##        self._initProperties(node)
137##        self._logger.info("WAeUP tool imported.")
138##
Note: See TracBrowser for help on using the repository browser.