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