1 | #-*- mode: python; mode: fold -*- |
---|
2 | # $Id: exportimport.py 3006 2008-01-10 09:36:13Z henrik $ |
---|
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 | """ |
---|
14 | import csv,re |
---|
15 | |
---|
16 | # Zope3 component architecture |
---|
17 | from zope.app import zapi |
---|
18 | from zope.component import adapts |
---|
19 | from zope.interface import implements |
---|
20 | |
---|
21 | # Standard GenericSetup base classes and functions |
---|
22 | from Products.GenericSetup.utils import exportObjects |
---|
23 | from Products.GenericSetup.utils import importObjects |
---|
24 | from Products.GenericSetup.utils import XMLAdapterBase |
---|
25 | from Products.GenericSetup.utils import PropertyManagerHelpers |
---|
26 | |
---|
27 | from 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). |
---|
31 | from Products.GenericSetup.interfaces import IBody |
---|
32 | from Products.GenericSetup.interfaces import ISetupEnviron |
---|
33 | from Products.WAeUP_SRP.interfaces import IWAeUPTool |
---|
34 | import Globals |
---|
35 | p_home = Globals.package_home(globals()) |
---|
36 | i_home = Globals.INSTANCE_HOME |
---|
37 | |
---|
38 | TOOL = 'portal_waeup' |
---|
39 | NAME = 'waeup' |
---|
40 | |
---|
41 | def 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 | |
---|
60 | def 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 | |
---|
71 | def 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 | campus.manage_setLocalGroupRoles(groupid='CampusOfficers', |
---|
82 | roles=('SectionOfficer',)) |
---|
83 | if academics is not None: |
---|
84 | academics.manage_setLocalGroupRoles(groupid='role:Authenticated', |
---|
85 | roles=('SectionReader',)) |
---|
86 | academics.manage_setLocalGroupRoles(groupid='AcademicsOfficers', |
---|
87 | roles=('SectionOfficer',)) |
---|
88 | if students is not None: |
---|
89 | students.manage_setLocalGroupRoles(groupid = 'StudentsReaders', |
---|
90 | roles=('SectionReader',)) |
---|
91 | students.manage_setLocalGroupRoles(groupid = 'ClearanceOfficers', |
---|
92 | roles=('SectionReader',)) |
---|
93 | students.manage_setLocalGroupRoles(groupid = 'CourseAdvisers', |
---|
94 | roles=('SectionReader',)) |
---|
95 | students.manage_setLocalGroupRoles(groupid='MemberAdmins', |
---|
96 | roles=('SectionOfficer',)) |
---|
97 | students.manage_setLocalGroupRoles(groupid='StudentsOfficers', |
---|
98 | roles=('SectionOfficer',)) |
---|
99 | students.manage_setLocalGroupRoles(groupid = 'role:Student', |
---|
100 | roles=('SectionReader',)) |
---|
101 | if accommodation is not None: |
---|
102 | accommodation.manage_setLocalGroupRoles(groupid='role:Student', |
---|
103 | roles=('SectionReader',)) |
---|
104 | accommodation.manage_setLocalGroupRoles(groupid='AccommodationOfficers', |
---|
105 | roles=('SectionOfficer',)) |
---|
106 | members = getattr(site.portal_directories,'members') |
---|
107 | if members is not None: |
---|
108 | members.manage_setLocalGroupRoles(groupid='MemberAdmins', |
---|
109 | roles=('SectionOfficer',)) |
---|
110 | students = getattr(site.portal_directories,'students') |
---|
111 | if students is not None: |
---|
112 | students.manage_setLocalGroupRoles(groupid='MemberAdmins', |
---|
113 | roles=('SectionOfficer',)) |
---|
114 | waeup_stacking_dir = getattr(site.portal_directories,'waeup_stacking_dir') |
---|
115 | if waeup_stacking_dir is not None: |
---|
116 | waeup_stacking_dir.manage_setLocalGroupRoles(groupid='MemberAdmins', |
---|
117 | roles=('SectionOfficer',)) |
---|
118 | |
---|
119 | ## pm.setLocalGroupRoles(campus.academics,['role:Authenticated', |
---|
120 | ## ],'SectionReader') |
---|
121 | importWAeUPTable(site.portal_accommodation, '', context,'accommodation') |
---|
122 | importWAeUPTable(site.courses_catalog, '', context,'courses_catalog') |
---|
123 | importWAeUPTable(site.payments_catalog, '', context,'payments_catalog') |
---|
124 | importWAeUPTable(site.online_payments_import, '', context,'online_payments_import') |
---|
125 | importWAeUPTable(site.portal_pins, '', context,'pins') |
---|
126 | importWAeUPTable(site.portal_pumeresults, '', context,'pumeresults') |
---|
127 | importWAeUPTable(site.returning_import, '', context,'returning_import') |
---|
128 | importWAeUPTable(site.results_import, '', context,'results_import') |
---|
129 | importWAeUPTable(site.students_catalog, '', context,'students_catalog') |
---|
130 | importWAeUPTable(site.applicants_catalog, '', context,'applicants_catalog') |
---|
131 | importWAeUPTable(site.course_results, '', context,'course_results') |
---|
132 | importWAeUPTable(site.portal_catalog, '', context,'portal_catalog') |
---|
133 | importWAeUPTable(site.portal_catalog_real, '', context,'portal_catalog_real') |
---|
134 | |
---|
135 | site.students_catalog.manage_setLocalGroupRoles(groupid='CampusOfficers', |
---|
136 | roles=('SectionOfficer',)) |
---|
137 | site.payments_catalog.manage_setLocalGroupRoles(groupid='CampusOfficers', |
---|
138 | roles=('SectionOfficer',)) |
---|
139 | site.applicants_catalog.manage_setLocalGroupRoles(groupid='CampusOfficers', |
---|
140 | roles=('SectionOfficer',)) |
---|
141 | site.course_results.manage_setLocalGroupRoles(groupid='CampusOfficers', |
---|
142 | roles=('SectionOfficer',)) |
---|
143 | |
---|
144 | site.portal_catalog.id = 'portal_catalog' |
---|
145 | site.portal_catalog_real.id = 'portal_catalog_real' |
---|
146 | |
---|
147 | |
---|
148 | from Products.CPSCore.exportimport.catalog import CatalogToolXMLAdapter |
---|
149 | #from Products.GenericSetup.ZCatalog.exportimport import ZCatalogXMLAdapter |
---|
150 | |
---|
151 | from interfaces import IWAeUPTable |
---|
152 | |
---|
153 | class WAeUPTableXMLAdapter(CatalogToolXMLAdapter): |
---|
154 | #class WAeUPTableXMLAdapter(ZCatalogXMLAdapter): |
---|
155 | __used_for__ = IWAeUPTable |
---|
156 | _LOGGER_ID = 'waeup_table' |
---|
157 | |
---|
158 | ## def _importNode(self, node): |
---|
159 | ## """Import the object from the DOM node. |
---|
160 | ## """ |
---|
161 | ## if self.environ.shouldPurge(): |
---|
162 | ## self._purgeProperties() |
---|
163 | ## self._purgeObjects() |
---|
164 | ## self._purgeIndexes() |
---|
165 | ## self._purgeColumns() |
---|
166 | ## |
---|
167 | ## self._logger.info('Catalog imported.') |
---|
168 | # This the XMLAdapter itself. It encodes the im- / export logic that is specific |
---|
169 | # to our tool. `im- / exportObjects` functions will find it thanks to the zope |
---|
170 | # components machinery and the associations made in the configure.zcml file. |
---|
171 | |
---|
172 | ##class WAeUPXMLAdapter(XMLAdapterBase, PropertyManagerHelpers): |
---|
173 | ## """XML importer and exporter for the WAeUP tool. |
---|
174 | ## |
---|
175 | ## Hence this XMLAdapter is really simple. To get more complete examples of |
---|
176 | ## what XMLAdapters are meant to do, please have a look at the |
---|
177 | ## CPSSkins.exportimport.py or CPSDirectory.exportimport.py files, for |
---|
178 | ## instance. |
---|
179 | ## """ |
---|
180 | ## |
---|
181 | ## adapts(IWAeUPTool, ISetupEnviron) |
---|
182 | ## implements(IBody) |
---|
183 | ## |
---|
184 | ## _LOGGER_ID = NAME |
---|
185 | ## name = NAME |
---|
186 | ## |
---|
187 | ## def _exportNode(self): |
---|
188 | ## """Export the object as a DOM node. |
---|
189 | ## """ |
---|
190 | ## node = self._getObjectNode('object') |
---|
191 | ## node.appendChild(self._extractProperties()) |
---|
192 | ## self._logger.info("WAeUP tool exported.") |
---|
193 | ## return node |
---|
194 | ## |
---|
195 | ## def _importNode(self, node): |
---|
196 | ## """Import the object from the DOM node. |
---|
197 | ## """ |
---|
198 | ## if self.environ.shouldPurge(): |
---|
199 | ## self._purgeProperties() |
---|
200 | ## self._initProperties(node) |
---|
201 | ## self._logger.info("WAeUP tool imported.") |
---|
202 | ## |
---|