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

Last change on this file since 2826 was 2408, checked in by mylan, 14 years ago

#131: Added uninstallation profile. Unregister from local site manager news-sitemap schema extender adapters.

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