source: WAeUP_SRP/trunk/exportimport.py @ 967

Last change on this file since 967 was 966, checked in by joachim, 18 years ago

created new catalog pumeresults for pumeresult checking
modified pume_anon_view and pume_anon_slip to use it.

  • Property svn:keywords set to Id
File size: 5.9 KB
Line 
1#-*- mode: python; mode: fold -*-
2# $Id: exportimport.py 966 2006-11-29 14:26:31Z joachim $
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"""
14import csv,re
15
16# Zope3 component architecture
17from zope.app import zapi
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
33from Products.WAeUP_SRP.interfaces import IWAeUPTool
34import Globals
35p_home = Globals.package_home(globals())
36i_home = Globals.INSTANCE_HOME
37
38TOOL = 'portal_waeup'
39NAME = 'waeup'
40
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
60def exportWAeUP(context):
61    """Export our WAeUP tool configuration
62    """
63    site = context.getSite()
64    tool = getattr(context,"campus",None)
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()
75    pm = site.portal_membership
76    campus = getattr(site.portal_url.getPortalObject(),'campus',None)
77    if campus is not None:
78        academics = getattr(campus,'academics',None)
79        students = getattr(campus,'students',None)
80        accommodation = getattr(campus,'accommodation',None)
81        if academics is not None:
82            academics.manage_setLocalGroupRoles(groupid='role:Authenticated',
83                                         roles=('SectionReader',))
84        if students is not None:
85            students.manage_setLocalGroupRoles(groupid = 'ClearanceOfficers',
86                                              roles=('SectionReader',))
87            students.manage_setLocalGroupRoles(groupid = 'role:Student',
88                                              roles=('SectionReader',))
89        if accommodation is not None:
90            accommodation.manage_setLocalGroupRoles(groupid='role:Student',
91                                         roles=('SectionReader',))                                             
92    members = getattr(site.portal_directories,'members')
93    if members is not None:
94        members.manage_setLocalGroupRoles(groupid='MemberAdmins',
95                                         roles=('SectionOfficer',))
96
97##    pm.setLocalGroupRoles(campus.academics,['role:Authenticated',
98##                                           ],'SectionReader')
99    importWAeUPTable(site.portal_accommodation, '', context,'accommodation')
100    importWAeUPTable(site.portal_pins, '', context,'pins')
101    importWAeUPTable(site.portal_pumeresults, '', context,'pumeresults')
102
103from Products.CPSCore.exportimport.catalog import CatalogToolXMLAdapter
104#from Products.GenericSetup.ZCatalog.exportimport import ZCatalogXMLAdapter
105
106from interfaces import IWAeUPTable
107
108class WAeUPTableXMLAdapter(CatalogToolXMLAdapter):
109#class WAeUPTableXMLAdapter(ZCatalogXMLAdapter):
110    __used_for__ = IWAeUPTable
111    _LOGGER_ID = 'waeup_table'
112
113##    def _importNode(self, node):
114##        """Import the object from the DOM node.
115##        """
116##        if self.environ.shouldPurge():
117##            self._purgeProperties()
118##            self._purgeObjects()
119##            self._purgeIndexes()
120##            self._purgeColumns()
121##
122##        self._logger.info('Catalog imported.')
123# This the XMLAdapter itself. It encodes the im- / export logic that is specific
124# to our tool. `im- / exportObjects` functions will find it thanks to the zope
125# components machinery and the associations made in the configure.zcml file.
126
127##class WAeUPXMLAdapter(XMLAdapterBase, PropertyManagerHelpers):
128##    """XML importer and exporter for the WAeUP tool.
129##
130##    Hence this XMLAdapter is really simple. To get more complete examples of
131##    what XMLAdapters are meant to do, please have a look at the
132##    CPSSkins.exportimport.py or CPSDirectory.exportimport.py files, for
133##    instance.
134##    """
135##
136##    adapts(IWAeUPTool, ISetupEnviron)
137##    implements(IBody)
138##
139##    _LOGGER_ID = NAME
140##    name = NAME
141##
142##    def _exportNode(self):
143##        """Export the object as a DOM node.
144##        """
145##        node = self._getObjectNode('object')
146##        node.appendChild(self._extractProperties())
147##        self._logger.info("WAeUP tool exported.")
148##        return node
149##
150##    def _importNode(self, node):
151##        """Import the object from the DOM node.
152##        """
153##        if self.environ.shouldPurge():
154##            self._purgeProperties()
155##        self._initProperties(node)
156##        self._logger.info("WAeUP tool imported.")
157##
Note: See TracBrowser for help on using the repository browser.