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.qPloneTabs.config import * |
---|
8 | |
---|
9 | configlets = ({'id':PROJECT_NAME, |
---|
10 | 'name':'Plone Tabs', |
---|
11 | 'action':'string:${portal_url}/prefs_tabs_form', |
---|
12 | 'condition':'', |
---|
13 | 'category':'Products', |
---|
14 | 'visible':1, |
---|
15 | 'appId':PROJECT_NAME, |
---|
16 | 'permission':VIEW_PERMISSION, |
---|
17 | 'imageUrl':'qplonetabs.gif' },) |
---|
18 | |
---|
19 | def setupSkin(self, out, skinFolder): |
---|
20 | """ Setup product skin layer """ |
---|
21 | |
---|
22 | skinstool=getToolByName(self, 'portal_skins') |
---|
23 | for skin in skinstool.getSkinSelections(): |
---|
24 | path = skinstool.getSkinPath(skin) |
---|
25 | path = map(string.strip, string.split(path,',')) |
---|
26 | if not skinFolder in path: |
---|
27 | try: |
---|
28 | path.insert( path.index('custom')+1, skinFolder) |
---|
29 | except ValueError: |
---|
30 | path.append(skinFolder) |
---|
31 | path = string.join(path, ', ') |
---|
32 | skinstool.addSkinSelection(skin, path) |
---|
33 | out.write(' %s layer sucessfully installed into skin %s.\n' % (skinFolder, skin)) |
---|
34 | else: |
---|
35 | out.write(' %s layer was already installed into skin %s.\n' % (skinFolder, skin)) |
---|
36 | |
---|
37 | def removeSkin(self, skins=[]): |
---|
38 | """ Setup product skin layer """ |
---|
39 | |
---|
40 | if skins: |
---|
41 | skinstool = getToolByName(self, 'portal_skins') |
---|
42 | for skinName in skinstool.getSkinSelections(): |
---|
43 | path = skinstool.getSkinPath(skinName) |
---|
44 | path = [i.strip() for i in path.split(',')] |
---|
45 | for s in skins: |
---|
46 | if s in path: |
---|
47 | path.remove(s) |
---|
48 | s += '/' |
---|
49 | for layer in path: |
---|
50 | if layer.startswith(s): |
---|
51 | path.remove(layer) |
---|
52 | path = ','.join(path) |
---|
53 | skinstool.addSkinSelection(skinName, path) |
---|
54 | |
---|
55 | def addConfiglet(self, out): |
---|
56 | """ Add tabs configlet to portal control panel """ |
---|
57 | |
---|
58 | configTool = getToolByName(self, 'portal_controlpanel', None) |
---|
59 | if configTool: |
---|
60 | for conf in configlets: |
---|
61 | configTool.registerConfiglet(**conf) |
---|
62 | out.write('Added configlet %s\n' % conf['id']) |
---|
63 | |
---|
64 | def removeConfiglet(self, out): |
---|
65 | """ Remove tabs configlet from portal control panel """ |
---|
66 | |
---|
67 | configTool = getToolByName(self, 'portal_controlpanel', None) |
---|
68 | if configTool: |
---|
69 | for conf in configlets: |
---|
70 | configTool.unregisterConfiglet(conf['id']) |
---|
71 | out.write('Removed configlet %s\n' % conf['id']) |
---|
72 | |
---|
73 | def install(self): |
---|
74 | """ Product installation """ |
---|
75 | |
---|
76 | out = StringIO() |
---|
77 | |
---|
78 | out.write('setupSkin... \n') |
---|
79 | skinstool = getToolByName(self, 'portal_skins') |
---|
80 | addDirectoryViews(skinstool, SKINS_DIR, GLOBALS) |
---|
81 | setupSkin(self, out, PROJECT_NAME) |
---|
82 | |
---|
83 | mtool = getToolByName(self, 'portal_migration') |
---|
84 | plone_version = mtool.getFileSystemVersion() |
---|
85 | if plone_version == '2.0.5': |
---|
86 | setupSkin(self, out, PROJECT_NAME+'/2.0.5') |
---|
87 | out.write('Added %s/2.0.5 Layer to portal_skins\n' % PROJECT_NAME) |
---|
88 | |
---|
89 | addConfiglet(self, out) |
---|
90 | |
---|
91 | return out.getvalue() |
---|
92 | |
---|
93 | def uninstall(self): |
---|
94 | """ Product uninstallation """ |
---|
95 | |
---|
96 | out = StringIO() |
---|
97 | |
---|
98 | removeConfiglet(self, out) |
---|
99 | |
---|
100 | out.write('removeSkin... \n') |
---|
101 | removeSkin(self, [PROJECT_NAME, PROJECT_NAME+'/2.0.5']) |
---|
102 | |
---|
103 | return out.getvalue() |
---|