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