Commit f669903f authored by Rafael Monnerat's avatar Rafael Monnerat 👻

TemplateTool: Simplify compareVersions

  Use packaging library for compare versions, intead mantain
  our own code. This should be also future proof in case
  version definition evolve.
parent 2d814f2a
...@@ -39,6 +39,7 @@ import shutil ...@@ -39,6 +39,7 @@ import shutil
import sys import sys
import six import six
from packaging.version import Version
from Acquisition import Implicit, Explicit from Acquisition import Implicit, Explicit
from AccessControl import ClassSecurityInfo from AccessControl import ClassSecurityInfo
from AccessControl.SecurityInfo import ModuleSecurityInfo from AccessControl.SecurityInfo import ModuleSecurityInfo
...@@ -1101,33 +1102,13 @@ class TemplateTool (BaseTool): ...@@ -1101,33 +1102,13 @@ class TemplateTool (BaseTool):
- 1.1 < 2.0 - 1.1 < 2.0
- 1.0.0 = 1.0 - 1.0.0 = 1.0
""" """
r = re.compile(r'(\d+|[a-zA-Z])') version1_object = Version(version1)
v1 = r.findall(version1) version2_object = Version(version2)
v2 = r.findall(version2) if version1 < version2:
return -1
def convert(v, i): elif version1 == version2:
"""Convert the ith element of v to an interger for a comparison. return 0
""" return 1
#LOG('convert', 0, 'v = %r, i = %r' % (v, i))
try:
e = v[i]
try:
e = int(e)
except ValueError:
# ASCII code is one byte, so this produces negative.
e = struct.unpack('b', e.encode())[0] - 0x200
except IndexError:
e = 0
return e
for i in xrange(max(len(v1), len(v2))):
e1 = convert(v1, i)
e2 = convert(v2, i)
result = cmp(e1, e2)
if result != 0:
return result
return 0
def _getBusinessTemplateUrlDict(self): def _getBusinessTemplateUrlDict(self):
business_template_url_dict = {} business_template_url_dict = {}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment