source: products/quintagroup.plonegooglesitemaps/trunk/quintagroup/plonegooglesitemaps/Extensions/Install.py

Last change on this file was 3510, checked in by potar, 12 years ago

Merged sitemap_date branch into trunk

  • Property svn:eol-style set to native
File size: 2.2 KB
RevLine 
[2384]1import logging
[1593]2from Products.CMFCore.utils import getToolByName
[2376]3from Products.GenericSetup.upgrade import _upgrade_registry
[1593]4
[2384]5logger = logging.getLogger("quintagroup.plonegooglesitemaps")
[1593]6PROFILE = "profile-quintagroup.plonegooglesitemaps:default"
[2408]7UNINSTALL = "profile-quintagroup.plonegooglesitemaps:uninstall"
[1593]8
[3152]9
[1593]10def install(self, reinstall=False):
11    """ Install skin with GenericSetup install profile
12    """
13    ps = getToolByName(self, 'portal_setup')
14    mtool = getToolByName(self, 'portal_migration')
15    plone_version = mtool.getFileSystemVersion()
[2376]16    isPlone3 = plone_version.startswith('3')
17    isPlone4 = plone_version.startswith('4')
[1593]18
[2376]19    if reinstall and (isPlone3 or isPlone4):
20        step = None
21        profile_id = 'quintagroup.plonegooglesitemaps:default'
[3510]22        steps_to_run = [s['id'] for s in
[3152]23                        ps.listUpgrades(profile_id, show_old=False)]
[2376]24        for step_id in steps_to_run:
25            step = _upgrade_registry.getUpgradeStep(profile_id, step_id)
[2384]26            step.doStep(ps)
[3152]27            msg = "Ran upgrade step %s for profile %s" \
28                  % (step.title, profile_id)
[2376]29            logger.log(logging.INFO, msg)
30        # We update the profile version to the last one we have reached
31        # with running an upgrade step.
32        if step and step.dest is not None and step.checker is None:
[3152]33            ps.setLastVersionForProfile(profile_id, step.dest)
[2376]34        return "Ran all reinstall steps."
35
36    if (isPlone3 or isPlone4):
[1593]37        # if this is plone 3.x
38        (ps.aq_base).__of__(self).runAllImportStepsFromProfile(PROFILE)
39    else:
40        active_context_id = ps.getImportContextID()
41        ps.setImportContext(PROFILE)
42        ps.runAllImportSteps()
43        ps.setImportContext(active_context_id)
[2408]44
45
46def uninstall(portal, reinstall=False):
47    """ Uninstall this product.
48
[3152]49        This external method is need, because portal_quickinstaller doens't
50        know what GenericProfile profile to apply when uninstalling a product.
[2408]51    """
52    setup_tool = getToolByName(portal, 'portal_setup')
53    if reinstall:
54        return "Ran all reinstall steps."
55    else:
56        setup_tool.runAllImportStepsFromProfile(UNINSTALL)
57        return "Ran all uninstall steps."
Note: See TracBrowser for help on using the repository browser.