source: waeup_product/trunk/exportimport.py @ 204

Last change on this file since 204 was 200, checked in by joachim, 19 years ago

=removed files not necessary

File size: 7.0 KB
Line 
1#-*- mode: python; mode: fold -*-
2# $Id: exportimport.py 31640 2006-01-15 19:22:29Z ogrisel $
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"""
14
15# Zope3 component architecture
16from zope.component import adapts
17from zope.interface import implements
18
19# Standard GenericSetup base classes and functions
20from Products.GenericSetup.utils import exportObjects
21from Products.GenericSetup.utils import importObjects
22from Products.GenericSetup.utils import XMLAdapterBase
23from Products.GenericSetup.utils import PropertyManagerHelpers
24
25from Products.CMFCore.utils import getToolByName
26
27# GenericSetup multi adapts a class that implement IWAeUP and a particular
28# ISetupEnvironment to and IBody (piece of XML configuration).
29from Products.GenericSetup.interfaces import IBody
30from Products.GenericSetup.interfaces import ISetupEnviron
31from Products.WAeUP.interfaces import IWAeUPTool
32
33TOOL = 'portal_waeup'
34NAME = 'waeup'
35
36# The exportWAeUP and importWAeUP methods are called by the specific
37# im- / export steps defined in the corresponding XML files in the
38# WAeUP/profiles/default/ directory.
39
40
41def setupStructure(context): ###(
42    sections = getattr(context,'sections')
43    portal = getattr(sections,'uniportal',None)
44    if portal is None:
45        sections.invokeFactory('University','uniportal')
46        portal = getattr(context,'uniportal',None)
47        portal.getContent().edit(mapping={'Title':SRPP_TITLE})
48    students =  getattr(portal,'students',None)
49    if students is None:
50        portal.invokeFactory('StudentsFolder','students')
51        students = getattr(portal,'students').getContent()
52        students.edit(mapping={'Title':'Students'})
53    academics = getattr(portal,'academics',None)
54    if academics is None:
55        portal.invokeFactory('AcademicsFolder','academics')
56        academics = getattr(portal,'academics')
57        academics.getContent().edit(mapping={'Title':'Academics'})
58    installFaculties(academics)
59    if not hasattr(portal,'accommodation'):
60        portal.invokeFactory('AccoFolder','accommodation')
61        accommodation = getattr(portal,'accommodation').getContent()
62        accommodation.edit(mapping={'Title':'Accommodation'})
63###)
64
65
66def installFaculties( academics): ###(
67    """install Universityspecific Faculies with Departments"""
68    faculties = [
69##                     {'id': 'agri', ###(
70##                      'Title': 'Agriculture',
71##                      'departments': [
72##                                     { 'id': 'dep1', ###(
73##                                       'Title': 'One',
74##                                     },
75##                                     ],
76##                      },###)
77                  { 'id': 'science',
78                  'Title': 'Science',
79                  'departments': [
80                                 { 'id': 'bio', ###(
81                                   'Title': 'Biochemistry',
82                                 },
83                                 { 'id': 'bot',
84                                   'Title': 'Botany',
85                                 },
86                                 { 'id': 'che',
87                                   'Title': 'Chemistry',
88                                 },
89                                 { 'id': 'com',
90                                   'Title': 'Computer Science',
91                                 },
92                                 { 'id': 'geo',
93                                   'Title': 'Geologie',
94                                 },
95                                 { 'id': 'mat',
96                                   'Title': 'Mathematics',
97                                 },
98                                 { 'id': 'mic',
99                                   'Title': 'Microbiology',
100                                 },
101                                 { 'id': 'opt',
102                                   'Title': 'Optometry',
103                                 },
104                                 { 'id': 'phy',
105                                   'Title': 'Physics',
106                                 },
107                                 { 'id': 'zoo',
108                                   'Title': 'Zoology',
109                                 },
110                                 ],
111                  },###)
112                 ]###)
113    for faculty in faculties:
114        fid = faculty['id']
115        f = getattr(academics,fid,None)
116        if f is None:
117            #self.log('Creating Faculty %(id)s = %(Title)s' % faculty)
118            academics.invokeFactory('Faculty', fid)
119            f = getattr(academics,fid)
120            f.getContent().edit(mapping=faculty)
121        for department in faculty['departments']:
122            #self.log('Checking Department %(id)s = %(Title)s' % department)
123            did = department['id']
124            d = getattr(f,did,None)
125            if d is None:
126                #self.log('Creating Department %(id)s = %(Title)s' % department)
127                f.invokeFactory('Department', did)
128                d = getattr(f,did)
129                d.getContent().edit(mapping=department)
130###)
131
132
133def exportWAeUP(context):
134    """Export our WAeUP tool configuration
135    """
136    site = context.getSite()
137    tool = getToolByName(site, TOOL, None)
138    if tool is None:
139        logger = context.getLogger(NAME)
140        logger.info("Nothing to export.")
141        return
142    exportObjects(tool, '', context)
143
144def importWAeUP(context):
145    """Import WAeUP tool configuration
146    """
147    site = context.getSite()
148    setupStructure(site)
149    pass
150    #site = context.getSite()
151    #tool = getToolByName(site, TOOL)
152    #importObjects(tool, '', context)
153
154
155# This the XMLAdapter itself. It encodes the im- / export logic that is specific
156# to our tool. `im- / exportObjects` functions will find it thanks to the zope
157# components machinery and the associations made in the configure.zcml file.
158
159class WAeUPXMLAdapter(XMLAdapterBase, PropertyManagerHelpers):
160    """XML importer and exporter for the WAeUP tool.
161
162    Hence this XMLAdapter is really simple. To get more complete examples of
163    what XMLAdapters are meant to do, please have a look at the
164    CPSSkins.exportimport.py or CPSDirectory.exportimport.py files, for
165    instance.
166    """
167
168    adapts(IWAeUPTool, ISetupEnviron)
169    implements(IBody)
170
171    _LOGGER_ID = NAME
172    name = NAME
173
174    def _exportNode(self):
175        """Export the object as a DOM node.
176        """
177        node = self._getObjectNode('object')
178        node.appendChild(self._extractProperties())
179        self._logger.info("WAeUP tool exported.")
180        return node
181
182    def _importNode(self, node):
183        """Import the object from the DOM node.
184        """
185        if self.environ.shouldPurge():
186            self._purgeProperties()
187        self._initProperties(node)
188        self._logger.info("WAeUP tool imported.")
189
Note: See TracBrowser for help on using the repository browser.