source: products/quintagroup.dropdownmenu/tags/1.2.0.2/quintagroup/dropdownmenu/setuphandlers.py @ 3560

Last change on this file since 3560 was 2876, checked in by mylan, 14 years ago

#232: Fixed uninstallation. Added unisntallation with QI

  • Property svn:eol-style set to native
File size: 1.9 KB
Line 
1import sys
2import logging
3from zope.component import queryUtility
4from zope.component import getSiteManager
5from zope.component import getGlobalSiteManager
6from plone.registry.interfaces import IRegistry
7from plone.browserlayer.utils import unregister_layer
8from plone.browserlayer.interfaces import ILocalBrowserLayerType
9
10from Acquisition import aq_parent
11from Products.CMFCore.utils import getToolByName
12
13from quintagroup.dropdownmenu.interfaces import IDropDownMenuSettings
14from quintagroup.dropdownmenu import PROJECT_NAME, logger
15
16
17def removeConfiglet(site):
18    """ Remove configlet.
19    """
20    conf_id = "dropdownmenu"
21    controlpanel_tool = getToolByName(site, 'portal_controlpanel')
22    if controlpanel_tool:
23        controlpanel_tool.unregisterConfiglet(conf_id)
24        logger.log(logging.INFO, "Unregistered \"%s\" configlet." % conf_id)
25
26def cleanupRegistry(site):
27    registry = queryUtility(IRegistry)
28    iprefix = IDropDownMenuSettings.__identifier__ + '.'
29    delrecs = [r for r in registry.records.keys() if r.startswith(iprefix)]
30    map(registry.records.__delitem__, delrecs)
31    logger.log(logging.INFO, "Removed %s items from plone.app.registry" % delrecs)
32
33def fixQIUninstallDependencies(site):
34    """Uninstallation procedure of Quickinstaller tool clean-up settings,
35       made by dependent products. Fix this issue.
36    """
37    qi = getToolByName(site, 'portal_quickinstaller')
38    qiprod = getattr(qi, PROJECT_NAME, None)
39    if qiprod:
40        utilities = getattr(qiprod, 'utilities', [])
41        todel = filter(lambda k:not sum(map(lambda i:PROJECT_NAME in i, k)), utilities)
42        for u in todel:
43            uidx = utilities.index(u)
44            del utilities[uidx]
45
46def uninstall(context):
47    """ Do customized uninstallation.
48    """
49    if context.readDataFile('quintagroup_dropdownmenu_uninstall.txt') is None:
50        return
51
52    site = context.getSite()
53    fixQIUninstallDependencies(site)
54    removeConfiglet(site)
55    cleanupRegistry(site)
56
Note: See TracBrowser for help on using the repository browser.