CleanupTemp n'existe plus.
[GroupUserFolder.git] / Extensions / Install.py
1 # -*- coding: utf-8 -*-
2 ## GroupUserFolder
3 ## Copyright (C)2006 Ingeniweb
4
5 ## This program is free software; you can redistribute it and/or modify
6 ## it under the terms of the GNU General Public License as published by
7 ## the Free Software Foundation; either version 2 of the License, or
8 ## (at your option) any later version.
9
10 ## This program is distributed in the hope that it will be useful,
11 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 ## GNU General Public License for more details.
14
15 ## You should have received a copy of the GNU General Public License
16 ## along with this program; see the file COPYING. If not, write to the
17 ## Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 """
19
20 """
21 __version__ = "$Revision: $"
22 # $Source: $
23 # $Id: Install.py 30098 2006-09-08 12:35:01Z encolpe $
24 __docformat__ = 'restructuredtext'
25
26 from Products.GroupUserFolder import groupuserfolder_globals
27 from Products.GroupUserFolder.GroupUserFolder import GroupUserFolder
28 from StringIO import StringIO
29 from Products.CMFCore.utils import getToolByName
30 from Products.CMFCore.DirectoryView import addDirectoryViews
31 from Acquisition import aq_base
32 from OFS.Folder import manage_addFolder
33
34
35 SKIN_NAME = "gruf"
36 _globals = globals()
37
38 def install_plone(self, out):
39 pass
40
41 def install_subskin(self, out, skin_name=SKIN_NAME, globals=groupuserfolder_globals):
42 print >>out, " Installing subskin."
43 skinstool=getToolByName(self, 'portal_skins')
44 if skin_name not in skinstool.objectIds():
45 print >>out, " Adding directory view for GRUF"
46 addDirectoryViews(skinstool, 'skins', globals)
47
48 for skinName in skinstool.getSkinSelections():
49 path = skinstool.getSkinPath(skinName)
50 path = [i.strip() for i in path.split(',')]
51 try:
52 if skin_name not in path:
53 path.insert(path.index('custom') +1, skin_name)
54 except ValueError:
55 if skin_name not in path:
56 path.append(skin_name)
57
58 path = ','.join(path)
59 skinstool.addSkinSelection( skinName, path)
60 print >>out, " Done installing subskin."
61
62 def walk(out, obj, operation):
63 if obj.isPrincipiaFolderish:
64 for content in obj.objectValues():
65 walk(out, content, operation)
66 operation(out, obj)
67
68
69 def migrate_user_folder(obj, out, ):
70 """
71 Move a user folder into a temporary folder, create a GroupUserFolder,
72 and then move the old user folder into the Users portion of the GRUF.
73 NOTE: You cant copy/paste between CMF and Zope folder. *sigh*
74 """
75 id = obj.getId()
76 if id == 'acl_users':
77 if obj.__class__.__name__ == "GroupUserFolder":
78 # Avoid already-created GRUFs
79 print >>out, " Do NOT migrate acl_users at %s, as it is already a GroupUserFolder" % ('/'.join( obj.getPhysicalPath() ), )
80 return out.getvalue()
81
82 print >>out, " Migrating acl_users folder at %s to a GroupUserFolder" % ('/'.join( obj.getPhysicalPath() ), )
83
84 container = obj.aq_parent
85
86 # Instead of using Copy/Paste we hold a reference to the acl_users
87 # and use that reference instead of physically moving objects in ZODB
88 tmp_users=container._getOb('acl_users')
89 tmp_allow=container.__allow_groups__
90
91 del container.__allow_groups__
92 if 'acl_users' in container.objectIds():
93 container.manage_delObjects('acl_users')
94
95 container.manage_addProduct['GroupUserFolder'].manage_addGroupUserFolder()
96 container.acl_users.Users.manage_delObjects( 'acl_users' )
97 container.acl_users.Users._setObject('acl_users', aq_base(tmp_users))
98 container.__allow_groups__ = aq_base(getattr(container,'acl_users'))
99
100 return out.getvalue()
101
102
103 def migrate_plone_site_to_gruf(self, out = None):
104 if out is None:
105 out = StringIO()
106 print >>out, " Attempting to migrate UserFolders to GroupUserFolders..."
107 urltool=getToolByName(self, 'portal_url')
108 plonesite = urltool.getPortalObject()
109 ## We disable the 'walk' operation because if the acl_users object is deep inside
110 ## the Plone site, that is a real problem. Furthermore, that may be because
111 ## we're already digging an GRUF and have the risk to update a GRUF/User/acl_users
112 ## object !
113 ## walk(out, plonesite, migrate_user_folder)
114 for obj in plonesite.objectValues():
115 migrate_user_folder(obj, out, )
116 print >>out, " Done Migrating UserFolders to GroupUserFolders."
117 return out.getvalue()
118
119 def install(self):
120 out = StringIO()
121 print >>out, "Installing GroupUserFolder"
122 install_subskin(self, out)
123 install_plone(self, out)
124 migrate_plone_site_to_gruf(self, out)
125 print >>out, "Done."
126 return out.getvalue()