source: products/quintagroup.seoptimizer/trunk/quintagroup/seoptimizer/Extensions/Install.py @ 3223

Last change on this file since 3223 was 3134, checked in by zidane, 13 years ago

fixes pep8

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