Skip to content

Commit

Permalink
Merge 703df46 into 3f469d9
Browse files Browse the repository at this point in the history
  • Loading branch information
MrTango committed Oct 21, 2019
2 parents 3f469d9 + 703df46 commit b7dc25b
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 2 deletions.
5 changes: 3 additions & 2 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
Changelog
=========

5.0.2 (unreleased)
5.0.2 (2019-10-21)
------------------

- Nothing changed yet.
- Add auto increment version to upgrade_step sub-template
[MrTango]


5.0.1 (2019-10-18)
Expand Down
23 changes: 23 additions & 0 deletions bobtemplates/plone/upgrade_step.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,28 @@ def _read_source_version(configurator):
return int(match_result[0].text)


def _write_dest_version(configurator):
"""Add plone.app.dexterity dependency metadata.xml in Generic Setup profiles.""" # NOQA: E501
metadata_file_name = u'metadata.xml'
metadata_file_dir = u'profiles/default'
metadata_file_path = configurator.variables['package_folder'] + '/' + \
metadata_file_dir + '/' + metadata_file_name

with open(metadata_file_path, 'r') as xml_file:
parser = etree.XMLParser(remove_blank_text=True)
tree = etree.parse(xml_file, parser)
version = tree.xpath('/metadata/version')[0]
version.text = str(configurator.variables["upgrade_step_dest_version"])

with open(metadata_file_path, 'wb') as xml_file:
tree.write(
xml_file,
pretty_print=True,
xml_declaration=True,
encoding='utf-8',
)


def pre_renderer(configurator):
"""Pre rendering."""
configurator = base_prepare_renderer(configurator)
Expand All @@ -93,6 +115,7 @@ def post_renderer(configurator):
"""Post rendering."""
_update_package_configure_zcml(configurator)
_update_upgrades_configure_zcml(configurator)
_write_dest_version(configurator)
_remove_unwanted_files(configurator)
git_commit(
configurator,
Expand Down
34 changes: 34 additions & 0 deletions package_tests/test_upgrade_step.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,37 @@ def test_read_source_version(tmpdir):
)
assert configurator
assert upgrade_step._read_source_version(configurator) == 1004


def test_write_dest_version(tmpdir):
package_root = tmpdir.strpath + "/collective.todo"
package_path = init_package_base_structure(package_root)
target_path = os.path.join(package_path, 'profiles/default')

template = """<?xml version='1.0' encoding='UTF-8'?>
<metadata>
<version>1004</version>
<dependencies>
<dependency>profile-plone.app.dexterity:default</dependency>
</dependencies>
</metadata>
"""
with open(os.path.join(target_path, 'metadata.xml'), 'w') as f:
f.write(template)
configurator = Configurator(
template='bobtemplates.plone:upgrade_step',
target_directory=package_path,
bobconfig={
'non_interactive': True,
},
variables={
'plone.version': '5.1',
'package_folder': package_path,
'upgrade_step_title': 'Add cool index and reindex it',
'upgrade_step_dest_version': 1005,
'upgrade_step_description': 'We add an index and reindex it with existing content.',
},
)
assert configurator
upgrade_step._write_dest_version(configurator)
assert upgrade_step._read_source_version(configurator) == 1005

0 comments on commit b7dc25b

Please sign in to comment.