1 | import string |
---|
2 | from cStringIO import StringIO |
---|
3 | |
---|
4 | from Products.Archetypes import listTypes |
---|
5 | from Products.Archetypes.Extensions.utils import installTypes |
---|
6 | |
---|
7 | from Products.CMFCore.utils import getToolByName |
---|
8 | from Products.CMFCore.DirectoryView import addDirectoryViews |
---|
9 | |
---|
10 | from Products.qSiloGroup.config import * |
---|
11 | |
---|
12 | def removeSkin(self, layer): |
---|
13 | skinstool = getToolByName(self, 'portal_skins') |
---|
14 | for skinName in skinstool.getSkinSelections(): |
---|
15 | original_path = skinstool.getSkinPath(skinName) |
---|
16 | original_path = [l.strip() for l in original_path.split(',')] |
---|
17 | new_path= [] |
---|
18 | for l in original_path: |
---|
19 | if (l == layer) or (l.startswith(layer+'/')): |
---|
20 | continue |
---|
21 | new_path.append(l) |
---|
22 | skinstool.addSkinSelection(skinName, ','.join(new_path)) |
---|
23 | |
---|
24 | def setupSkin(self, out, skinFolder): |
---|
25 | |
---|
26 | skinstool=getToolByName(self, 'portal_skins') |
---|
27 | |
---|
28 | addDirectoryViews(skinstool, SKINS_DIR, GLOBALS) |
---|
29 | |
---|
30 | for skin in skinstool.getSkinSelections(): |
---|
31 | path = skinstool.getSkinPath(skin) |
---|
32 | path = map( string.strip, string.split( path,',' ) ) |
---|
33 | |
---|
34 | if not skinFolder in path: |
---|
35 | try: |
---|
36 | path.insert( path.index( 'custom')+1, skinFolder ) |
---|
37 | except ValueError: |
---|
38 | path.append(skinFolder) |
---|
39 | path = string.join( path, ', ' ) |
---|
40 | skinstool.addSkinSelection( skin, path ) |
---|
41 | out.write(' %s layer sucessfully installed into skin %s.\n' % (skinFolder, skin)) |
---|
42 | else: |
---|
43 | out.write(' %s layer was already installed into skin %s.\n' % (skinFolder, skin)) |
---|
44 | |
---|
45 | def setupActions(self, out): |
---|
46 | out.write("Inspecting portal_types\n") |
---|
47 | types_tool = getToolByName(self, 'portal_types') |
---|
48 | for ptype in types_tool.objectValues(): |
---|
49 | if ptype.getId() == 'Folder': |
---|
50 | action_obj = ptype.getActionObject('object/edit_silo_navigation') |
---|
51 | if action_obj is None: |
---|
52 | out.write( ' Added Silo Navigation tab for %s\n' % ptype.getId() ) |
---|
53 | ptype.addAction('edit_silo_navigation', |
---|
54 | 'Silo Navigation', |
---|
55 | 'string:${object_url}/silo_navigation_form', |
---|
56 | '', |
---|
57 | ('Modify portal content',), |
---|
58 | 'object', |
---|
59 | visible=True) |
---|
60 | else: |
---|
61 | action_obj.edit(title=title, action=action, |
---|
62 | condition=condition, |
---|
63 | permissions=tuple(permissions), |
---|
64 | visible=visible) |
---|
65 | def removeActions(self): |
---|
66 | tool = getToolByName(self, 'portal_types') |
---|
67 | for ptype in tool.objectValues(): |
---|
68 | if ptype.getId() == 'Folder': |
---|
69 | action = ptype.getActionObject('object/edit_silo_navigation') |
---|
70 | if action != None: |
---|
71 | acts = list(ptype.listActions()) |
---|
72 | ptype.deleteActions([acts.index(a) for a in acts if a.getId()=='edit_silo_navigation']) |
---|
73 | |
---|
74 | def setupResources(self, out): |
---|
75 | portal_js = getToolByName(self, 'portal_javascripts', None) |
---|
76 | portal_css = getToolByName(self, 'portal_css', None) |
---|
77 | |
---|
78 | if portal_js is not None: |
---|
79 | scripts = portal_js.getResourceIds() |
---|
80 | for script in JS: |
---|
81 | if script['id'] not in scripts: |
---|
82 | portal_js.registerScript(**script) |
---|
83 | print >> out, 'Registered %s script\n' % script['id'] |
---|
84 | else: |
---|
85 | print >> out, 'Skipped registering of %s script\n' % script['id'] |
---|
86 | |
---|
87 | if portal_css is not None: |
---|
88 | csses = portal_css.getResourceIds() |
---|
89 | for css in CSS: |
---|
90 | if css['id'] not in csses: |
---|
91 | portal_css.registerStylesheet(**css) |
---|
92 | print >> out, 'Registered %s css\n' % script['id'] |
---|
93 | else: |
---|
94 | print >> out, 'Skipped registering of %s css\n' % script['id'] |
---|
95 | |
---|
96 | def install(self): |
---|
97 | out = StringIO() |
---|
98 | |
---|
99 | out.write('setupSkin... \n') |
---|
100 | setupSkin(self, out, PROJECTNAME) |
---|
101 | |
---|
102 | installTypes(self, out, listTypes(PROJECTNAME), PROJECTNAME) |
---|
103 | print >> out, 'Type Installed' |
---|
104 | |
---|
105 | setupActions(self, out) |
---|
106 | |
---|
107 | setupResources(self, out) |
---|
108 | |
---|
109 | # setup our GenericSetup profile |
---|
110 | setup_tool = getToolByName(self, 'portal_setup') |
---|
111 | setup_tool.runAllImportStepsFromProfile('profile-Products.qSiloGroup:qsilogroup') |
---|
112 | |
---|
113 | return out.getvalue() |
---|
114 | |
---|
115 | def uninstall(self): |
---|
116 | out = StringIO() |
---|
117 | |
---|
118 | removeActions(self) |
---|
119 | |
---|
120 | removeSkin(self, PROJECTNAME) |
---|
121 | |
---|
122 | return out.getvalue() |
---|