[1516] | 1 | import logging |
---|
[1515] | 2 | from Products.CMFCore.utils import getToolByName |
---|
| 3 | |
---|
[1516] | 4 | logger = logging.getLogger('quintagroup.seoptimizer') |
---|
| 5 | |
---|
[1830] | 6 | def removeSkin(site, layer): |
---|
[1515] | 7 | """ Remove layers. |
---|
| 8 | """ |
---|
[1830] | 9 | skins_tool = getToolByName(site, 'portal_skins') |
---|
| 10 | for skinName in skins_tool.getSkinSelections(): |
---|
| 11 | skin_paths = skins_tool.getSkinPath(skinName).split(',') |
---|
| 12 | paths = [l.strip() for l in skin_paths if not (l == layer or l.startswith(layer+'/'))] |
---|
| 13 | logger.log(logging.INFO, "Removed layers from %s skin." % skinName) |
---|
| 14 | skins_tool.addSkinSelection(skinName, ','.join(paths)) |
---|
[1515] | 15 | |
---|
[1830] | 16 | def removeActions(site): |
---|
[1515] | 17 | """ Remove actions. |
---|
| 18 | """ |
---|
[1830] | 19 | types_tool = getToolByName(site, 'portal_types') |
---|
| 20 | for ptype in types_tool.objectValues(): |
---|
| 21 | idxs = [idx_act[0] for idx_act in enumerate(ptype.listActions()) if idx_act[1].id == 'seo_properties'] |
---|
| 22 | if idxs: |
---|
| 23 | ptype.deleteActions(idxs) |
---|
| 24 | logger.log(logging.INFO, "Deleted \"SEO Properties\" action for %s type." % ptype.id) |
---|
[1515] | 25 | |
---|
[1830] | 26 | def removeConfiglet(site, conf_id): |
---|
| 27 | """ Remove configlet. |
---|
[1515] | 28 | """ |
---|
[1830] | 29 | controlpanel_tool = getToolByName(site, 'portal_controlpanel') |
---|
| 30 | if controlpanel_tool: |
---|
| 31 | controlpanel_tool.unregisterConfiglet(conf_id) |
---|
| 32 | logger.log(logging.INFO, "Unregistered \"%s\" configlet." % conf_id) |
---|
[1515] | 33 | |
---|
[1570] | 34 | def importVarious(context): |
---|
| 35 | """ Do customized installation. |
---|
| 36 | """ |
---|
| 37 | if context.readDataFile('seo_install.txt') is None: |
---|
| 38 | return |
---|
| 39 | |
---|
| 40 | def uninstall(context): |
---|
[1515] | 41 | """ Do customized uninstallation. |
---|
| 42 | """ |
---|
| 43 | if context.readDataFile('seo_uninstall.txt') is None: |
---|
| 44 | return |
---|
| 45 | site = context.getSite() |
---|
[1570] | 46 | removeSkin(site, 'quintagroup.seoptimizer' ) |
---|
| 47 | removeActions(site) |
---|
[1830] | 48 | removeConfiglet(site, 'quintagroup.seoptimizer') |
---|