Skip to content

Commit

Permalink
Allow to register upgrade steps in multiple directories
Browse files Browse the repository at this point in the history
  • Loading branch information
ale-rt committed Jun 29, 2022
1 parent 64f811e commit 3ff718e
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 7 deletions.
6 changes: 4 additions & 2 deletions docs/HISTORY.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ Changelog
=========


3.3.1 (unreleased)
3.4.0 (unreleased)
------------------

- Nothing changed yet.
- Added the possibility to group upgrade steps in subdirectories.
Fixes `issue 217 <https://github.com/4teamwork/ftw.upgrade/issues/217>`.
[ale-rt]


3.3.0 (2022-03-28)
Expand Down
33 changes: 29 additions & 4 deletions ftw/upgrade/directory/zcml.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
import zope.schema


MIN_VERSION = str(10 ** 13)


class IUpgradeStepDirectoryDirective(Interface):

profile = zope.schema.TextLine(
Expand Down Expand Up @@ -45,7 +48,7 @@ def upgrade_step_directory_handler(context, profile, directory,
.split(os.sep))

context.action(
discriminator=('upgrade-step:directory', profile),
discriminator=('upgrade-step:directory', profile, directory),
callable=upgrade_step_directory_action,
args=(profile, dottedname, context.path(directory),
soft_dependencies))
Expand All @@ -62,7 +65,14 @@ def upgrade_step_directory_action(profile, dottedname, path,
' upgrade step directory.'.format(profile))

profileinfo = _profile_registry.getProfileInfo(profile)
if profileinfo.get('version', None) is not None:

# Check that no version is set for the profile in the metadata.xml
# The profile can still have a version set by ftw.upgrade in a previous run
# of this action
if (
"ftw.upgrade:dependencies" not in profileinfo
and profileinfo.get("version", None) is not None
):
raise UpgradeStepConfigurationError(
'Registering an upgrades directory for "{0}" requires this profile'
' to not define a version in its metadata.xml.'
Expand Down Expand Up @@ -105,7 +115,22 @@ def upgrade_step_directory_action(profile, dottedname, path,
last_version = upgrade_info['target-version']

profile = GlobalRegistryStorage(IProfile).get(profile)
profile['version'] = last_version
profile['version'] = max(last_version, profile.get('version', MIN_VERSION))

# Combine the soft dependencies with the one we might have already
# due to this action setting them in a previous run
existing_soft_dependencies = profile.get('ftw.upgrade:dependencies')
if existing_soft_dependencies:
if soft_dependencies:
soft_dependencies = (
[
dependency for dependency in soft_dependencies
if dependency not in existing_soft_dependencies
] + existing_soft_dependencies
)
else:
soft_dependencies = existing_soft_dependencies

profile['ftw.upgrade:dependencies'] = soft_dependencies


Expand All @@ -126,4 +151,4 @@ def find_start_version(profile):
if dests:
return max(dests)
else:
return str(10 ** 13)
return MIN_VERSION
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from setuptools import setup, find_packages
import os

version = '3.3.1.dev0'
version = '3.4.0.dev0'

tests_require = [
'ftw.testing >= 2.0.0.dev0',
Expand Down

0 comments on commit 3ff718e

Please sign in to comment.