[Checkins] SVN: Products.GenericSetup/trunk/Products/GenericSetup/
Use the parse_version function from pkg_resources to
normalize versions before comparing them inside
Hanno Schlichting
plone at hannosch.info
Sat Apr 12 16:14:46 EDT 2008
Log message for revision 85287:
Use the parse_version function from pkg_resources to normalize versions before comparing them inside
the upgrade code. This ensures pre-release versions are handled correctly.
Changed:
U Products.GenericSetup/trunk/Products/GenericSetup/CHANGES.txt
U Products.GenericSetup/trunk/Products/GenericSetup/upgrade.py
-=-
Modified: Products.GenericSetup/trunk/Products/GenericSetup/CHANGES.txt
===================================================================
--- Products.GenericSetup/trunk/Products/GenericSetup/CHANGES.txt 2008-04-12 20:01:51 UTC (rev 85286)
+++ Products.GenericSetup/trunk/Products/GenericSetup/CHANGES.txt 2008-04-12 20:14:46 UTC (rev 85287)
@@ -2,6 +2,10 @@
GenericSetup 1.5.0 (unreleased)
+ - Use the parse_version function from pkg_resources to normalize versions
+ before comparing them inside the upgrade code. This ensures pre-release
+ versions are handled correctly.
+
- Fixed the upgrade step directive schema. Description is not required.
- Introduced a new IComponentsHandlerBlacklist interface. You can register
Modified: Products.GenericSetup/trunk/Products/GenericSetup/upgrade.py
===================================================================
--- Products.GenericSetup/trunk/Products/GenericSetup/upgrade.py 2008-04-12 20:01:51 UTC (rev 85286)
+++ Products.GenericSetup/trunk/Products/GenericSetup/upgrade.py 2008-04-12 20:14:46 UTC (rev 85287)
@@ -11,10 +11,20 @@
#
##############################################################################
+from pkg_resources import parse_version
from BTrees.OOBTree import OOBTree
from registry import _profile_registry
+
+def normalize_version(version):
+ if isinstance(version, tuple):
+ version = '.'.join(version)
+ if version in (None, 'unknown', 'all'):
+ return version
+ return parse_version(version)
+
+
class UpgradeRegistry(object):
"""Registry of upgrade steps, by profile.
@@ -92,9 +102,8 @@
self.profile = profile
def versionMatch(self, source):
- return (source is None or
- self.source is None or
- source <= self.source)
+ return (source is None or self.source is None or
+ normalize_version(source) <= normalize_version(self.source))
def isProposed(self, tool, source):
"""Check if a step can be applied.
@@ -129,7 +138,8 @@
proposed = step.isProposed(tool, source)
if (not proposed
and source is not None
- and (step.source is None or source > step.source)):
+ and (step.source is None or
+ normalize_version(source) > normalize_version(step.source))):
return
info = {
'id': id,
More information about the Checkins
mailing list