summaryrefslogtreecommitdiffstats
path: root/cnucnu/helper.py
diff options
context:
space:
mode:
authorTill Maas <opensource@till.name>2009-07-27 00:30:05 +0200
committerTill Maas <opensource@till.name>2009-07-27 00:30:05 +0200
commitf6a79cdf8f1b37bf4809a6e9195e2cad178987a2 (patch)
treeaa0bf519c6099dccd47826a60f89afac782a589e /cnucnu/helper.py
parent1b12906c56fc7fe168006018c64e845f7ecb36bb (diff)
downloadcnucnu-f6a79cdf8f1b37bf4809a6e9195e2cad178987a2.tar.gz
cnucnu-f6a79cdf8f1b37bf4809a6e9195e2cad178987a2.tar.xz
cnucnu-f6a79cdf8f1b37bf4809a6e9195e2cad178987a2.zip
handly release candidates in upstream versions
Diffstat (limited to 'cnucnu/helper.py')
-rw-r--r--cnucnu/helper.py42
1 files changed, 41 insertions, 1 deletions
diff --git a/cnucnu/helper.py b/cnucnu/helper.py
index ab81e34..5ba9d1c 100644
--- a/cnucnu/helper.py
+++ b/cnucnu/helper.py
@@ -28,12 +28,52 @@ def get_html(url):
def rpm_cmp(v1, v2):
import rpm
- return rpm.labelCompare((None, v1, None), (None, v2, None))
+ diff = rpm.labelCompare((None, v1, None), (None, v2, None))
+ return diff
def rpm_max(list):
list.sort(cmp=rpm_cmp)
return list[-1]
+def cnucnu_cmp(v1, v2):
+ import rpm
+
+ v1, rc1 = split_rc(v1)
+ v2, rc2 = split_rc(v2)
+
+ diff = rpm_cmp(v1, v2)
+ # base versions are the same, check for rc-status
+ if diff == 0:
+ # both are rc, higher rc is newer
+ if rc1 and rc2:
+ return cmp(rc1, rc2)
+ # only first is rc, then second is newer
+ elif rc1:
+ return -1
+ # only second is rc, then first is newer
+ elif rc2:
+ return 1
+ # none is rc, both are the same
+ else:
+ return 0
+ # base versions are different, ignore rc-status
+ else:
+ return diff
+
+def split_rc(version):
+ import re
+ RC = re.compile("([^-r]*)(-?rc([0-9]))?")
+ match = RC.match(version)
+
+ v, ignore, rc = match.groups()
+
+ return (v, rc)
+
+def cnucnu_max(list):
+ list.sort(cmp=cnucnu_cmp)
+ return list[-1]
+
+
""" return a dict that only contains keys that are in key_list
"""
def filter_dict(d, key_list):