source: products/quintagroup.seoptimizer/branches/refactoring2.3.0/quintagroup/seoptimizer/Extensions/Install.py @ 1850

Last change on this file since 1850 was 1850, checked in by liebster, 14 years ago

#159: Added upgrade steps from earlier version package to 3.0.0.

  • Property svn:eol-style set to native
File size: 1.9 KB
Line 
1import logging
2from Products.CMFCore.utils import getToolByName
3from Products.GenericSetup.upgrade import _upgrade_registry
4
5from quintagroup.seoptimizer.config import PROJECT_NAME
6
7logger = logging.getLogger('quintagroup.seoptimizer')
8
9# our GenericSetup profile names
10INSTALL = 'profile-%s:default' % PROJECT_NAME
11UNINSTALL = 'profile-%s:uninstall' % PROJECT_NAME
12
13def install(portal, reinstall=False):
14    """ (Re)Install this product.
15
16        This external method is need, because portal_quickinstaller doens't know
17        what GenericProfile profile to apply when reinstalling a product.
18    """
19    setup_tool = getToolByName(portal, 'portal_setup')
20    if reinstall:
21        step = None
22        profile_id = 'quintagroup.seoptimizer:default'
23        steps_to_run = [s['id'] for s in setup_tool.listUpgrades(profile_id, show_old=False)]
24        for step_id in steps_to_run:
25            step = _upgrade_registry.getUpgradeStep(profile_id, step_id)
26            step.doStep(setup_tool)
27            msg = "Ran upgrade step %s for profile %s" % (step.title, profile_id)
28            logger.log(logging.INFO, msg)
29        # We update the profile version to the last one we have reached
30        # with running an upgrade step.
31        if step and step.dest is not None and step.checker is None:
32           setup_tool.setLastVersionForProfile(profile_id, step.dest)
33        return "Ran all reinstall steps."
34    else:
35        setup_tool.runAllImportStepsFromProfile(INSTALL)
36        return "Ran all install steps."
37
38def uninstall(portal, reinstall=False):
39    """ Uninstall this product.
40
41        This external method is need, because portal_quickinstaller doens't know
42        what GenericProfile profile to apply when uninstalling a product.
43    """
44    setup_tool = getToolByName(portal, 'portal_setup')
45    if reinstall:
46        return "Ran all reinstall steps."
47    else:
48        setup_tool.runAllImportStepsFromProfile(UNINSTALL)
49        return "Ran all uninstall steps."
Note: See TracBrowser for help on using the repository browser.