File: Install.py

package info (click to toggle)
zope-textindexng2 1%3A2.2.0-5
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 2,888 kB
  • ctags: 1,598
  • sloc: ansic: 6,836; python: 6,596; xml: 185; makefile: 137; sh: 41
file content (108 lines) | stat: -rw-r--r-- 3,689 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
###########################################################################
#
# TextIndexNG                The next generation TextIndex for Zope
#
# This software is governed by a license. See
# LICENSE.txt for the terms of this license.
#
###########################################################################


from StringIO import StringIO

from Products.CMFCore.utils import getToolByName
from Products.CMFCore.CMFCorePermissions import ManagePortal
from Products.CMFCore.DirectoryView import addDirectoryViews
from Products.TextIndexNG2 import textindexng_globals


configlets = \
( { 'id'         : 'TextIndexNG2'
  , 'name'       : 'TextIndexNG2 maintenance'
  , 'action'     : 'string:txng_maintenance'
  , 'category'   : 'Plone'
  , 'appId'      : 'TextIndexNG2'
  , 'permission' : ManagePortal
  , 'imageUrl'   : 'index.gif'
  }
,
)

def install(self):                                       
    out = StringIO()

    skins_tool = getToolByName(self, 'portal_skins')

    # Setup the skins
    if 'textindexng' not in skins_tool.objectIds():
        addDirectoryViews(skins_tool, 'skins',  textindexng_globals)
        out.write("Added textindexng skin directory view to portal_skins\n")

    # Now we need to go through the skin configurations and insert
    # 'textindexng' into the configurations.  Preferably, this should be
    # right before where 'content' is placed.  Otherwise, we append
    # it to the end.
    skins = skins_tool.getSkinSelections()

    for skin in skins:
        path = skins_tool.getSkinPath(skin)
        path = [p.strip() for p in  path.split(',')]

        if 'textindexng' not in path:
            try: path.insert(0, 'textindexng')
            except ValueError:
                path.append('textindexng')
                
            path = ', '.join(path)
            # addSkinSelection will replace exissting skins as well.
            skins_tool.addSkinSelection(skin, path)
            out.write("Added 'textindexng' to %s skin\n" % skin)
        else:
            out.write("Skipping %s skin, 'textindexng' is already set up\n" % (
                skin))


    configTool = getToolByName(self, 'portal_controlpanel', None)
    if configTool:
        for conf in configlets:
            print >>out, 'Adding configlet %s\n' % conf['id']
            configTool.registerConfiglet(**conf)

    print >> out, "Successfully installed"  
    return out.getvalue()


def uninstall(self):                                       
    out = StringIO()

    configTool = getToolByName(self, 'portal_controlpanel', None)
    if configTool:
        for conf in configlets:
            print >>out, 'Removing configlet %s\n' % conf['id']
            configTool.unregisterConfiglet(conf['id'])

    skins_tool = getToolByName(self, 'portal_skins')

    # Now we need to go through the skin configurations and insert
    # 'textindexng' into the configurations.  Preferably, this should be
    # right before where 'content' is placed.  Otherwise, we append
    # it to the end.
    skins = skins_tool.getSkinSelections()

    for skin in skins:
        path = skins_tool.getSkinPath(skin)
        path = [p.strip() for p in  path.split(',')]

        if 'textindexng' in path:
            path.remove('textindexng')
                
            path = ', '.join(path)
            # addSkinSelection will replace exissting skins as well.
            skins_tool.addSkinSelection(skin, path)
            out.write("Removed 'textindexng' from %s skin\n" % skin)
        else:
            out.write("Skipping %s skin, 'textindexng' is removed set up\n" % (
                skin))

    print >> out, "Successfully uninstalled" 
    return out.getvalue()