Introduction du callback « progressHandlerCB ».
[Plinn.git] / setuphandlers.py
1 # -*- coding: utf-8 -*-
2 #######################################################################################
3 # Plinn - http://plinn.org #
4 # Copyright (C) 2005-2007 Benoît PIN <benoit.pin@ensmp.fr> #
5 # #
6 # This program is free software; you can redistribute it and/or #
7 # modify it under the terms of the GNU General Public License #
8 # as published by the Free Software Foundation; either version 2 #
9 # of the License, or (at your option) any later version. #
10 # #
11 # This program is distributed in the hope that it will be useful, #
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
14 # GNU General Public License for more details. #
15 # #
16 # You should have received a copy of the GNU General Public License #
17 # along with this program; if not, write to the Free Software #
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #
19 #######################################################################################
20 """ Plinn specific GenericSetup handlers
21
22
23
24 """
25
26 from Products.CMFCore.utils import getToolByName
27 from Products.PythonScripts.PythonScript import PythonScript
28
29 VARIOUS_FILENAME = 'various.py'
30
31
32 def importVarious(context) :
33 """ exec python code from setup python script """
34 site = context.getSite()
35 text = context.readDataFile(VARIOUS_FILENAME)
36
37 if not text : return
38
39 site._setPortalTypeName('CMF Site')
40
41 script = PythonScript('various')
42 script = script.__of__(site)
43 script.write(text)
44 out = script(site)
45
46 # clone current authenticated user into portal's acl_users
47 from AccessControl import getSecurityManager
48 sm = getSecurityManager()
49 user = sm.getUser()
50 mtool = getToolByName(site, 'portal_membership')
51 mtool.addMember(user.getId(), user._getPassword(), user.getRoles(), user.getDomains())
52
53 return out
54
55 def exportVarious(exportContext):
56 site = exportContext.getSite()
57
58 stool = getToolByName(site, 'portal_setup')
59 importContext = stool._getImportContext(stool.getBaselineContextID())
60
61 exportContext.writeDataFile( VARIOUS_FILENAME,
62 importContext.readDataFile(VARIOUS_FILENAME),
63 'text/plain' )
64
65 return 'Various Plinn settings exported.'