1 | import logging |
---|
2 | from Products.CMFCore.utils import getToolByName |
---|
3 | from Products.GenericSetup.upgrade import _upgrade_registry |
---|
4 | |
---|
5 | from quintagroup.seoptimizer.config import PROJECT_NAME |
---|
6 | |
---|
7 | logger = logging.getLogger('quintagroup.seoptimizer') |
---|
8 | |
---|
9 | # our GenericSetup profile names |
---|
10 | INSTALL = 'profile-%s:default' % PROJECT_NAME |
---|
11 | UNINSTALL = 'profile-%s:uninstall' % PROJECT_NAME |
---|
12 | |
---|
13 | def 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 | |
---|
38 | def 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." |
---|