-
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #411 from plone/MrTango/add-upgrate-step-template
Mr tango/add upgrate step template
- Loading branch information
Showing
16 changed files
with
431 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 0 additions & 16 deletions
16
bobtemplates/plone/addon/src/+package.namespace+/+package.name+/upgrades.zcml.bob
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
from bobtemplates.plone.base import base_prepare_renderer | ||
from bobtemplates.plone.base import git_commit | ||
from bobtemplates.plone.base import remove_unwanted_files | ||
from bobtemplates.plone.base import update_configure_zcml | ||
from lxml import etree | ||
|
||
|
||
def _update_package_configure_zcml(configurator): | ||
path = '{0}'.format( | ||
configurator.variables['package_folder'], | ||
) | ||
file_name = u'configure.zcml' | ||
match_xpath = "zope:include[@package='.upgrades']" | ||
match_str = '-*- extra stuff goes here -*-' | ||
insert_str = """ | ||
<include package=".upgrades" /> | ||
""" | ||
update_configure_zcml( | ||
configurator, | ||
path, | ||
file_name=file_name, | ||
match_xpath=match_xpath, | ||
match_str=match_str, | ||
insert_str=insert_str, | ||
) | ||
|
||
|
||
def _update_upgrades_configure_zcml(configurator): | ||
path = '{0}/upgrades'.format( | ||
configurator.variables['package_folder'], | ||
) | ||
file_name = u'configure.zcml' | ||
example_file_name = '{0}.example'.format(file_name) | ||
zcml_package_name = configurator.variables['upgrade_step_dest_version'] | ||
match_xpath = "zope:include[@package='.{0}']".format(zcml_package_name) | ||
match_str = '-*- extra stuff goes here -*-' | ||
insert_str = """ | ||
<include package=".{0}" /> | ||
""".format(zcml_package_name) | ||
update_configure_zcml( | ||
configurator, | ||
path, | ||
file_name=file_name, | ||
example_file_name=example_file_name, | ||
match_xpath=match_xpath, | ||
match_str=match_str, | ||
insert_str=insert_str, | ||
) | ||
|
||
|
||
def _remove_unwanted_files(configurator): | ||
file_paths = [] | ||
rel_file_paths = [ | ||
'/upgrades/configure.zcml.example', | ||
] | ||
base_path = configurator.variables['package_folder'] | ||
for rel_file_path in rel_file_paths: | ||
file_paths.append('{0}{1}'.format(base_path, rel_file_path)) | ||
remove_unwanted_files(file_paths) | ||
|
||
|
||
def _read_source_version(configurator): | ||
base_path = configurator.variables['package_folder'] | ||
rel_file_path = '/profiles/default/metadata.xml' | ||
metadata_path = '{0}{1}'.format(base_path, rel_file_path) | ||
with open(metadata_path, 'r') as xml_file: | ||
parser = etree.XMLParser(remove_blank_text=True) | ||
tree = etree.parse(xml_file, parser) | ||
tree_root = tree.getroot() | ||
match_xpath = "version" | ||
match_result = tree_root.findall(match_xpath) | ||
if not match_result: | ||
raise RuntimeError("source version not found in metadata.xml!") | ||
return | ||
return int(match_result[0].text) | ||
|
||
|
||
def pre_renderer(configurator): | ||
"""Pre rendering.""" | ||
configurator = base_prepare_renderer(configurator) | ||
configurator.variables['template_id'] = 'upgrade_step' | ||
upgrade_step_source_version = _read_source_version(configurator) | ||
upgrade_step_dest_version = upgrade_step_source_version + 1 | ||
configurator.variables['upgrade_step_source_version'] = upgrade_step_source_version | ||
configurator.variables['upgrade_step_dest_version'] = upgrade_step_dest_version | ||
configurator.variables['upgrade_step_id'] = str(upgrade_step_dest_version) | ||
configurator.target_directory = configurator.variables['package_folder'] | ||
|
||
|
||
def post_renderer(configurator): | ||
"""Post rendering.""" | ||
_update_package_configure_zcml(configurator) | ||
_update_upgrades_configure_zcml(configurator) | ||
_remove_unwanted_files(configurator) | ||
git_commit( | ||
configurator, | ||
'Add upgrade_step: {0}'.format( | ||
configurator.variables['upgrade_step_title'], | ||
), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
[questions] | ||
subtemplate_warning.question = Please commit your changes, before using a sub-template! Continue anyway? [n/y] | ||
subtemplate_warning.required = True | ||
subtemplate_warning.default = n | ||
subtemplate_warning.pre_ask_question = bobtemplates.plone.base:git_clean_state_check | ||
subtemplate_warning.post_ask_question = mrbob.hooks:validate_choices bobtemplates.plone.base:subtemplate_warning_post_question | ||
subtemplate_warning.choices = y|n | ||
subtemplate_warning.choices_delimiter = | | ||
|
||
upgrade_step_title.question = Upgrade step title | ||
upgrade_step_title.help = Give your upgrade step a meaningful title. | ||
upgrade_step_title.default = | ||
upgrade_step_title.required = True | ||
|
||
upgrade_step_description.question = Upgrade step description | ||
upgrade_step_description.help = Give your upgrade step a meaningful description. | ||
upgrade_step_description.default = | ||
upgrade_step_description.required = False | ||
|
||
[template] | ||
post_ask = bobtemplates.plone.base:set_global_vars | ||
pre_render = bobtemplates.plone.upgrade_step:pre_renderer | ||
post_render = bobtemplates.plone.upgrade_step:post_renderer |
25 changes: 25 additions & 0 deletions
25
bobtemplates/plone/upgrade_step/tests/test_upgrade_step_+upgrade_step_id+.py.bob
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# -*- coding: utf-8 -*- | ||
from plone.app.testing import setRoles | ||
from plone.app.testing import TEST_USER_ID | ||
from {{{package.dottedname}}}.testing import {{{package.uppercasename}}}_FUNCTIONAL_TESTING | ||
from {{{package.dottedname}}}.testing import {{{package.uppercasename}}}_INTEGRATION_TESTING | ||
|
||
import unittest | ||
|
||
|
||
class UpgradeStepIntegrationTest(unittest.TestCase): | ||
|
||
layer = {{{package.uppercasename}}}_INTEGRATION_TESTING | ||
|
||
def setUp(self): | ||
self.portal = self.layer['portal'] | ||
setRoles(self.portal, TEST_USER_ID, ['Manager']) | ||
|
||
|
||
class UpgradeStepFunctionalTest(unittest.TestCase): | ||
|
||
layer = {{{package.uppercasename}}}_FUNCTIONAL_TESTING | ||
|
||
def setUp(self): | ||
self.portal = self.layer['portal'] | ||
setRoles(self.portal, TEST_USER_ID, ['Manager']) |
24 changes: 24 additions & 0 deletions
24
bobtemplates/plone/upgrade_step/upgrades/+upgrade_step_id+.zcml.bob
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<configure xmlns="http://namespaces.zope.org/zope" | ||
xmlns:gs="http://namespaces.zope.org/genericsetup"> | ||
|
||
<gs:registerProfile name="{{{ upgrade_step_dest_version }}}" | ||
title="{{{ upgrade_step_title }}}" | ||
description='Configuration for version {{{ upgrade_step_dest_version }}}' | ||
for="Products.CMFPlone.interfaces.IMigratingPloneSiteRoot" | ||
provides="Products.GenericSetup.interfaces.EXTENSION" /> | ||
|
||
<gs:upgradeSteps source="{{{ upgrade_step_source_version }}}" | ||
destination="{{{ upgrade_step_dest_version }}}" | ||
profile="{{{ package.dottedname }}}:default"> | ||
|
||
<gs:upgradeStep title="{{{ upgrade_step_title }}}" | ||
description="{{{ upgrade_step_description }}}" | ||
handler=".v{{{ upgrade_step_dest_version }}}.upgrade" /> | ||
|
||
<gs:upgradeDepends title="{{{ upgrade_step_title }}} (GS profile)" | ||
description="{{{ upgrade_step_description }}}" | ||
import_profile="{{{ package.dottedname }}}.upgrades:{{{ upgrade_step_dest_version }}}" /> | ||
|
||
</gs:upgradeSteps | ||
|
||
</configure> |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
bobtemplates/plone/upgrade_step/upgrades/configure.zcml.example.bob
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<configure | ||
xmlns="http://namespaces.zope.org/zope" | ||
i18n_domain="{{{ package.dottedname }}}"> | ||
|
||
-*- extra stuff goes here -*- | ||
|
||
</configure> |
9 changes: 9 additions & 0 deletions
9
bobtemplates/plone/upgrade_step/upgrades/v+upgrade_step_id+.py.bob
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
from . import logger | ||
|
||
|
||
def upgrade(setup_tool=None): | ||
""" | ||
""" | ||
logger.info("Running upgrade (Python): {{{ upgrade_step_title }}}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.