1 | import string |
---|
2 | from cStringIO import StringIO |
---|
3 | |
---|
4 | from Products.CMFCore.utils import getToolByName |
---|
5 | from Products.CMFCore.DirectoryView import addDirectoryViews |
---|
6 | |
---|
7 | from Products.CMFPlone.migrations.migration_util import safeEditProperty |
---|
8 | from Products.qPloneTabs.config import * |
---|
9 | |
---|
10 | configlets = ({'id':PROJECTNAME, |
---|
11 | 'name':'Plone Tabs', |
---|
12 | 'action':'string:${portal_url}/prefs_tabs_form', |
---|
13 | 'condition':'', |
---|
14 | 'category':'Products', |
---|
15 | 'visible':1, |
---|
16 | 'appId':PROJECTNAME, |
---|
17 | 'permission':VIEW_PERMISSION, |
---|
18 | 'imageUrl':'qplonetabs.gif' },) |
---|
19 | |
---|
20 | def addPropertySheet(self, out): |
---|
21 | """ Add tabs_properties property sheet to portal_properties and some needed field to it """ |
---|
22 | portal_props = getToolByName(self, 'portal_properties') |
---|
23 | if not hasattr(portal_props, PROPERTY_SHEET): |
---|
24 | portal_props.addPropertySheet(PROPERTY_SHEET, SHEET_TITLE) |
---|
25 | out.write('Added %s property sheet to portal_properties\n' % PROPERTY_SHEET) |
---|
26 | else: |
---|
27 | out.write('Skipped adding %s property sheet to portal_properties\n' % PROPERTY_SHEET) |
---|
28 | sheet = getattr(portal_props, PROPERTY_SHEET) |
---|
29 | |
---|
30 | if not hasattr(sheet, FIELD_NAME): |
---|
31 | safeEditProperty(sheet, FIELD_NAME, PROPERTY_FIELD, 'lines') |
---|
32 | out.write('Added %s property field to %s property sheet\n' % (FIELD_NAME, PROPERTY_SHEET)) |
---|
33 | else: |
---|
34 | out.write('Skipped adding %s property field to %s property sheet\n' % (FIELD_NAME, PROPERTY_SHEET)) |
---|
35 | |
---|
36 | def setupSkin(self, out, skinFolder): |
---|
37 | """ Setup product skin layer """ |
---|
38 | |
---|
39 | skinstool=getToolByName(self, 'portal_skins') |
---|
40 | for skin in skinstool.getSkinSelections(): |
---|
41 | path = skinstool.getSkinPath(skin) |
---|
42 | path = map(string.strip, string.split(path,',')) |
---|
43 | if not skinFolder in path: |
---|
44 | try: |
---|
45 | path.insert( path.index('custom')+1, skinFolder) |
---|
46 | except ValueError: |
---|
47 | path.append(skinFolder) |
---|
48 | path = string.join(path, ', ') |
---|
49 | skinstool.addSkinSelection(skin, path) |
---|
50 | out.write(' %s layer sucessfully installed into skin %s.\n' % (skinFolder, skin)) |
---|
51 | else: |
---|
52 | out.write(' %s layer was already installed into skin %s.\n' % (skinFolder, skin)) |
---|
53 | |
---|
54 | def removeSkin(self, skins=[]): |
---|
55 | """ Setup product skin layer """ |
---|
56 | |
---|
57 | if skins: |
---|
58 | skinstool = getToolByName(self, 'portal_skins') |
---|
59 | for skinName in skinstool.getSkinSelections(): |
---|
60 | path = skinstool.getSkinPath(skinName) |
---|
61 | path = [i.strip() for i in path.split(',')] |
---|
62 | for s in skins: |
---|
63 | if s in path: |
---|
64 | path.remove(s) |
---|
65 | s += '/' |
---|
66 | for layer in path: |
---|
67 | if layer.startswith(s): |
---|
68 | path.remove(layer) |
---|
69 | path = ','.join(path) |
---|
70 | skinstool.addSkinSelection(skinName, path) |
---|
71 | |
---|
72 | def addConfiglet(self, out): |
---|
73 | """ Add tabs configlet to portal control panel """ |
---|
74 | |
---|
75 | configTool = getToolByName(self, 'portal_controlpanel', None) |
---|
76 | if configTool: |
---|
77 | for conf in configlets: |
---|
78 | configTool.registerConfiglet(**conf) |
---|
79 | out.write('Added configlet %s\n' % conf['id']) |
---|
80 | |
---|
81 | def removeConfiglet(self, out): |
---|
82 | """ Remove tabs configlet from portal control panel """ |
---|
83 | |
---|
84 | configTool = getToolByName(self, 'portal_controlpanel', None) |
---|
85 | if configTool: |
---|
86 | for conf in configlets: |
---|
87 | configTool.unregisterConfiglet(conf['id']) |
---|
88 | out.write('Removed configlet %s\n' % conf['id']) |
---|
89 | |
---|
90 | def install(self): |
---|
91 | """ Product installation """ |
---|
92 | |
---|
93 | out = StringIO() |
---|
94 | |
---|
95 | out.write('setupSkin... \n') |
---|
96 | skinstool = getToolByName(self, 'portal_skins') |
---|
97 | addDirectoryViews(skinstool, SKINS_DIR, GLOBALS) |
---|
98 | setupSkin(self, out, PROJECTNAME) |
---|
99 | |
---|
100 | mtool = getToolByName(self, 'portal_migration') |
---|
101 | plone_version = mtool.getFileSystemVersion() |
---|
102 | if plone_version == '2.0.5': |
---|
103 | setupSkin(self, out, PROJECTNAME+'/2.0.5') |
---|
104 | out.write('Added %s/2.0.5 Layer to portal_skins\n' % PROJECTNAME) |
---|
105 | |
---|
106 | addPropertySheet(self, out) |
---|
107 | |
---|
108 | addConfiglet(self, out) |
---|
109 | |
---|
110 | return out.getvalue() |
---|
111 | |
---|
112 | def uninstall(self): |
---|
113 | """ Product uninstallation """ |
---|
114 | |
---|
115 | out = StringIO() |
---|
116 | |
---|
117 | removeConfiglet(self, out) |
---|
118 | |
---|
119 | out.write('removeSkin... \n') |
---|
120 | removeSkin(self, [PROJECTNAME, PROJECTNAME+'/2.0.5']) |
---|
121 | |
---|
122 | return out.getvalue() |
---|