source: products/qPloneTiles/tags/0.2/Extensions/Install.py @ 2683

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

Building directory structure

  • Property svn:eol-style set to native
File size: 3.7 KB
Line 
1import string
2from cStringIO import StringIO
3
4from Products.CMFCore.utils import getToolByName
5from Products.CMFCore.DirectoryView import addDirectoryViews
6
7from Products.qPloneTiles.config import *
8
9def registerJS(self, out, js_list=[]):
10    """ Register javascripts sources """
11
12    qi = getToolByName(self, 'portal_quickinstaller', None)
13    if qi is not None:
14        try:
15            if not qi.isProductInstalled('ResourceRegistries'):
16                qi.installProduct('ResourceRegistries', locked=0)
17            jsreg = getToolByName(self, 'portal_javascripts', None)
18            if jsreg is not None:
19                js_ids = jsreg.getResourceIds()
20                for js in js_list:
21                    if js not in js_ids:
22                        jsreg.manage_addScript(id=js,
23                                               expression="",
24                                               enabled=True,
25                                               cookable=True)
26                        out.write('Register %s... \n' % js)
27                    else:
28                        out.write('%s already exists... \n' % js)
29        except:
30            pass
31
32def unregisterJS(self, out, js_list=[]):
33    """ UnRegister javascripts sources """
34
35    qi = getToolByName(self, 'portal_quickinstaller', None)
36    if qi is not None:
37        try:
38            if not qi.isProductInstalled('ResourceRegistries'):
39                qi.installProduct('ResourceRegistries', locked=0)
40            jsreg = getToolByName(self, 'portal_javascripts', None)
41            if jsreg is not None:
42                js_ids = jsreg.getResourceIds()
43                for js in js_list:
44                    if js in js_ids:
45                        jsreg.manage_removeScript(id=js)
46                        out.write('Unregister %s... \n' % js)
47        except:
48            pass
49
50def setupSkin(self, out, skinFolder):
51    """ Setup product skin layer """
52
53    skinstool=getToolByName(self, 'portal_skins')
54    addDirectoryViews(skinstool, SKINS_DIR, GLOBALS)
55    for skin in skinstool.getSkinSelections():
56        path = skinstool.getSkinPath(skin)
57        path = map(string.strip, string.split(path,','))
58        if not skinFolder in path:
59            try:
60                path.insert( path.index('custom')+1, skinFolder)
61            except ValueError:
62                path.append(skinFolder)
63            path = string.join(path, ', ')
64            skinstool.addSkinSelection(skin, path)
65            out.write(%s layer sucessfully installed into skin %s.\n' % (skinFolder, skin))
66        else:
67            out.write(%s layer was already installed into skin %s.\n' % (skinFolder, skin))
68
69def removeSkin(self, skins=[]):
70    """ Setup product skin layer """
71
72    if skins:
73        skinstool = getToolByName(self, 'portal_skins')
74        for skinName in skinstool.getSkinSelections():
75            path = skinstool.getSkinPath(skinName)
76            path = [i.strip() for i in  path.split(',')]
77            for s in skins:
78                if s in path:
79                    path.remove(s)
80                s += '/'
81                for layer in path:
82                    if layer.startswith(s):
83                        path.remove(layer)
84            path = ','.join(path)
85            skinstool.addSkinSelection(skinName, path)
86
87
88def install(self):
89    """ Product installation """
90
91    out = StringIO()
92
93    # registering javascript sources
94    registerJS(self, out, JS_LIST)
95
96    # setup skin layer
97    out.write('setupSkin... \n')
98    setupSkin(self, out, PROJECT_NAME)
99
100    return out.getvalue()
101
102def uninstall(self):
103    """ Product uninstallation """
104
105    out = StringIO()
106
107    # unregistering javascript sources
108    unregisterJS(self, out, JS_LIST)
109
110    # remove skin layer
111    removeSkin(self, [PROJECT_NAME,])
112
113    return out.getvalue()
Note: See TracBrowser for help on using the repository browser.