diff options
author | Jon Turney <jon.turney@dronecode.org.uk> | 2021-03-14 22:36:17 +0300 |
---|---|---|
committer | Jon Turney <jon.turney@dronecode.org.uk> | 2021-03-14 22:36:42 +0300 |
commit | 30fb89cfc381589bc34412be3d8c150ea6eb10da (patch) | |
tree | f5f24c70dabe747bd5890bba78061725639a4c7a | |
parent | ed5a8f814447f0b2e7c12f9582d67546e871ffc0 (diff) |
Handle epoch (if present) in version comparison
-rw-r--r-- | calm/version.py | 18 | ||||
-rwxr-xr-x | test/test_calm.py | 5 |
2 files changed, 19 insertions, 4 deletions
diff --git a/calm/version.py b/calm/version.py index 508260e..17f8d0e 100644 --- a/calm/version.py +++ b/calm/version.py @@ -43,20 +43,25 @@ class SetupVersion: def __init__(self, version_string): self._version_string = version_string - # split version into [V, R], on the last '-', if any - split = list(itertools.chain(version_string.rsplit('-', 1), ['']))[:2] + # split release on the last '-', if any (default '') + v, r = list(itertools.chain(version_string.rsplit('-', 1), ['']))[:2] + + # split epoch, on the first ':', if any (default '0') + e, v = list(itertools.chain('0', v.split(':', 1)))[-2:] + + split = [e, v, r] # then split each part into numeric and alphabetic sequences # non-alphanumeric separators are discarded # numeric sequences have leading zeroes discarded - for j, i in enumerate(['V', 'R']): + for j, i in enumerate(['E', 'V', 'R']): sequences = re.finditer(r'(\d+|[a-zA-Z]+|[^a-zA-Z\d]+)', split[j]) sequences = [m for m in sequences if not re.match(r'[^a-zA-Z\d]+', m.group(1))] sequences = [re.sub(r'^0+(\d)', r'\1', m.group(1), 1) for m in sequences] setattr(self, '_' + i, sequences) def __str__(self): - return '%s (V=%s R=%s)' % (self._version_string, str(self._V), str(self._R)) + return '%s (E=%s V=%s R=%s)' % (self._version_string, str(self._E), str(self._V), str(self._R)) def __lt__(self, other): return self.__cmp__(other) == -1 @@ -65,6 +70,11 @@ class SetupVersion: return self.__cmp__(other) == 0 def __cmp__(self, other): + # compare E + c = SetupVersion._compare(self._E, other._E) + if c != 0: + return c + # compare V c = SetupVersion._compare(self._V, other._V) if c != 0: diff --git a/test/test_calm.py b/test/test_calm.py index 4c24313..7ea9718 100755 --- a/test/test_calm.py +++ b/test/test_calm.py @@ -220,6 +220,11 @@ class CalmTest(unittest.TestCase): ["0.6.7+20150214+git3a710f9-1", "0.6.7-1", 1], ["15.8b-1", "15.8.0.1-2", -1], ["1.2rc1-1", "1.2.0-2", -1], + ["20090325-1", "1:5.6.0-1", -1], + ["0:20090325-1", "1:5.6.0-1", -1], + ["2:20090325-1", "1:5.6.0-1", 1], + ["2:1.0-1", "1:5.6.0-1", 1], + ["1.0-1", "0:1.0-1", 0], # examples from https://fedoraproject.org/wiki/Archive:Tools/RPM/VersionComparison ["1.0010", "1.9", 1], ["1.05", "1.5", 0], |