1 | import logging |
---|
2 | from Products.CMFCore.utils import getToolByName |
---|
3 | from Products.GenericSetup.upgrade import _upgrade_registry |
---|
4 | |
---|
5 | logger = logging.getLogger("quintagroup.plonegooglesitemaps") |
---|
6 | PROFILE = "profile-quintagroup.plonegooglesitemaps:default" |
---|
7 | UNINSTALL = "profile-quintagroup.plonegooglesitemaps:uninstall" |
---|
8 | |
---|
9 | def 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() |
---|
15 | isPlone3 = plone_version.startswith('3') |
---|
16 | isPlone4 = plone_version.startswith('4') |
---|
17 | |
---|
18 | if reinstall and (isPlone3 or isPlone4): |
---|
19 | step = None |
---|
20 | profile_id = 'quintagroup.plonegooglesitemaps:default' |
---|
21 | steps_to_run = [s['id'] for s in ps.listUpgrades(profile_id, show_old=False)] |
---|
22 | for step_id in steps_to_run: |
---|
23 | step = _upgrade_registry.getUpgradeStep(profile_id, step_id) |
---|
24 | step.doStep(ps) |
---|
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: |
---|
30 | ps.setLastVersionForProfile(profile_id, step.dest) |
---|
31 | return "Ran all reinstall steps." |
---|
32 | |
---|
33 | if (isPlone3 or isPlone4): |
---|
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) |
---|
41 | |
---|
42 | |
---|
43 | def 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." |
---|