source: products/qSiloGroup/trunk/Extensions/Install.py @ 1

Last change on this file since 1 was 1, checked in by myroslav, 18 years ago

Building directory structure

  • Property svn:eol-style set to native
File size: 4.0 KB
Line 
1import string
2from cStringIO import StringIO
3
4from Products.Archetypes import listTypes
5from Products.Archetypes.Extensions.utils import installTypes
6
7from Products.CMFCore.utils import getToolByName
8from Products.CMFCore.DirectoryView import addDirectoryViews
9
10from Products.qSiloGroup.config import *
11
12def 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
24def 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
45def 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 = ptype.getActionById( 'edit_silo_navigation', default=None )
51            if action 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=1
60                               )
61def removeActions(self):
62    tool = getToolByName(self, 'portal_types')
63    for ptype in tool.objectValues():
64        if ptype.getId() == 'Folder':
65            action = ptype.getActionById( 'edit_silo_navigation', default=None )
66            if action != None:
67                acts = list(ptype.listActions())
68                ptype.deleteActions([acts.index(a) for a in acts if a.getId()=='edit_silo_navigation'])
69
70def setupResources(self, out):
71    portal_js = getToolByName(self, 'portal_javascripts', None)
72    portal_css = getToolByName(self, 'portal_css', None)
73   
74    if portal_js is not None:
75        scripts = portal_js.getResourceIds()
76        for script in JS:
77            if script['id'] not in scripts:
78                portal_js.registerScript(**script)
79                print >> out, 'Registered %s script\n' % script['id']
80            else:
81                print >> out, 'Skipped registering of %s script\n' % script['id']
82
83    if portal_css is not None:
84        csses = portal_css.getResourceIds()
85        for css in CSS:
86            if css['id'] not in csses:
87                portal_css.registerStylesheet(**css)
88                print >> out, 'Registered %s css\n' % script['id']
89            else:
90                print >> out, 'Skipped registering of %s css\n' % script['id']
91
92def install(self):
93    out = StringIO()
94
95    out.write('setupSkin... \n')
96    setupSkin(self, out, PROJECTNAME)
97
98    installTypes(self, out, listTypes(PROJECTNAME), PROJECTNAME)
99    print >> out, 'Type Installed'
100
101    setupActions(self, out)
102
103    setupResources(self, out)
104
105    return out.getvalue()
106
107def uninstall(self):
108    out = StringIO()
109
110    removeActions(self)
111
112    removeSkin(self, PROJECTNAME)
113
114    return out.getvalue()
Note: See TracBrowser for help on using the repository browser.