source: products/qPloneTabs/tags/0.1/Extensions/Install.py @ 1591

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

Building directory structure

  • Property svn:eol-style set to native
File size: 2.9 KB
Line 
1import string
2from cStringIO import StringIO
3
4from Products.CMFCore.utils import getToolByName
5from Products.CMFCore.DirectoryView import addDirectoryViews
6
7from Products.qPloneTabs.config import *
8
9configlets = ({'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
19def setupSkin(self, out, skinFolder):
20    """ Setup product skin layer """
21
22    skinstool=getToolByName(self, 'portal_skins')
23    addDirectoryViews(skinstool, SKINS_DIR, GLOBALS)
24    for skin in skinstool.getSkinSelections():
25        path = skinstool.getSkinPath(skin)
26        path = map(string.strip, string.split(path,','))
27        if not skinFolder in path:
28            try:
29                path.insert( path.index('custom')+1, skinFolder)
30            except ValueError:
31                path.append(skinFolder)
32            path = string.join(path, ', ')
33            skinstool.addSkinSelection(skin, path)
34            out.write(%s layer sucessfully installed into skin %s.\n' % (skinFolder, skin))
35        else:
36            out.write(%s layer was already installed into skin %s.\n' % (skinFolder, skin))
37
38def removeSkin(self, skins=[]):
39    """ Setup product skin layer """
40
41    if skins:
42        skinstool = getToolByName(self, 'portal_skins')
43        for skinName in skinstool.getSkinSelections():
44            path = skinstool.getSkinPath(skinName)
45            path = [i.strip() for i in  path.split(',')]
46            for s in skins:
47                if s in path:
48                    path.remove(s)
49                s += '/'
50                for layer in path:
51                    if layer.startswith(s):
52                        path.remove(layer)
53            path = ','.join(path)
54            skinstool.addSkinSelection(skinName, path)
55
56def addConfiglet(self, out):
57    """ Add tabs configlet to portal control panel """
58
59    configTool = getToolByName(self, 'portal_controlpanel', None)
60    if configTool:
61        for conf in configlets:
62            configTool.registerConfiglet(**conf)
63            out.write('Added configlet %s\n' % conf['id'])
64
65def removeConfiglet(self, out):
66    """ Remove tabs configlet from portal control panel """
67
68    configTool = getToolByName(self, 'portal_controlpanel', None)
69    if configTool:
70        for conf in configlets:
71            configTool.unregisterConfiglet(conf['id'])
72            out.write('Removed configlet %s\n' % conf['id'])
73
74def install(self):
75    """ Product installation """
76
77    out = StringIO()
78
79    addConfiglet(self, out)
80
81    out.write('setupSkin... \n')
82    setupSkin(self, out, PROJECT_NAME)
83
84    return out.getvalue()
85
86def uninstall(self):
87    """ Product uninstallation """
88
89    out = StringIO()
90
91    removeConfiglet(self, out)
92
93    out.write('removeSkin... \n')
94    removeSkin(self, [PROJECT_NAME,])
95
96    return out.getvalue()
Note: See TracBrowser for help on using the repository browser.