source: products/quintagroup.seoptimizer/trunk/quintagroup/seoptimizer/setuphandlers.py @ 1516

Last change on this file since 1516 was 1516, checked in by liebster, 14 years ago

Added import steps installation

File size: 2.7 KB
Line 
1import logging
2from Products.CMFCore.utils import getToolByName
3
4logger = logging.getLogger('quintagroup.seoptimizer')
5
6
7def migrationActions(site):
8    old = 'qseo_properties_edit_form'
9    new = '@@seo-context-properties'
10    for ptype in site.portal_types.objectValues():
11        acts = filter(lambda x: x.id == 'seo_properties' and old in x.getActionExpression(), ptype.listActions())
12        for act in acts:
13            ac_exp = act.getActionExpression()
14            if old in ac_exp:
15                act.setActionExpression(ac_exp.replace(old, new))
16                logger.log(logging.INFO, "For %s type changed URL Expression \"SEO Properties\" action's from %s to %s." % (ptype.id, old, new))
17
18def importVarious(context):
19    """ Do customized installation.
20    """
21    if context.readDataFile('seo_install.txt') is None:
22        return
23    site = context.getSite()
24    migrationActions(site)
25
26def removeSkin(self, layer):
27    """ Remove layers.
28    """
29    skinstool = getToolByName(self, 'portal_skins')
30    for skinName in skinstool.getSkinSelections():
31        original_path = skinstool.getSkinPath(skinName)
32        original_path = [l.strip() for l in original_path.split(',')]
33        new_path= []
34        for l in original_path:
35            if (l == layer) or (l.startswith(layer+'/')):
36                logger.log(logging.INFO, "Removed %s layer from %s skin." % (l, skinName))
37                continue
38            new_path.append(l)
39        skinstool.addSkinSelection(skinName, ','.join(new_path))
40
41def removeActions(self):
42    """ Remove actions.
43    """
44    tool = getToolByName(self, 'portal_types')
45    for ptype in tool.objectValues():
46        if ptype.getId() in ['File','Document','News Item']:
47            acts = filter(lambda x: x.id == 'seo_properties', ptype.listActions())
48            action = acts and acts[0] or None
49            if action != None:
50                acts = list(ptype.listActions())
51                ptype.deleteActions([acts.index(a) for a in acts if a.getId()=='seo_properties'])
52                logger.log(logging.INFO, "Deleted \"SEO Properties\" action for %s type." % ptype.id)
53
54def remove_configlets( context, conf_ids ):
55    """ Remove configlets.
56    """
57    configTool = getToolByName(context, 'portal_controlpanel', None)
58    if configTool:
59        for id in conf_ids:
60            configTool.unregisterConfiglet(id)
61            logger.log(logging.INFO, "Unregistered \"%s\" configlet." % id)
62
63def uninstall( context ):
64    """ Do customized uninstallation.
65    """
66    if context.readDataFile('seo_uninstall.txt') is None:
67        return
68    site = context.getSite()
69    removeSkin( site, 'quintagroup.seoptimizer' )
70    removeActions( site )
71    remove_configlets( site, ('quintagroup.seoptimizer',))
Note: See TracBrowser for help on using the repository browser.