From 11e2e30360a24bcc22ca4231fca495e5d846abb5 Mon Sep 17 00:00:00 2001 From: Bogdano Arendartchuk Date: Mon, 7 May 2007 21:51:40 +0000 Subject: Imported bm-2.1 from svn+ssh://svn.mandriva.com/svn/packages/cooker/bm/current/SOURCES/bm-2.1.tar.bz2 at r24959. --- BuildManager/rpmver.py | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 BuildManager/rpmver.py (limited to 'BuildManager/rpmver.py') diff --git a/BuildManager/rpmver.py b/BuildManager/rpmver.py new file mode 100644 index 0000000..cb3269c --- /dev/null +++ b/BuildManager/rpmver.py @@ -0,0 +1,62 @@ +# compare alpha and numeric segments of two versions +# return 1: first is newer than second +# 0: first and second are the same version +# -1: second is newer than first +def rpmVersionCompare(e1, v1, r1, e2, v2, r2): + if e1 and not e2: + return 1 + if not e1 and e2: + return -1 + if e1 and e2: + if e1 < e2: + return -1 + if e1 > e2: + return 1 + rc = rpmvercmp(v1, v2) + if rc: return rc + return rpmvercmp(r1, r2) + +# compare alpha and numeric segments of two versions +# return 1: a is newer than b +# 0: a and b are the same version +# -1: b is newer than a +def rpmvercmp(a, b): + if a == b: + return 0 + ai = 0 + bi = 0 + la = len(a) + lb = len(b) + while ai < la and bi < lb: + while ai < la and not a[ai].isalnum(): ai += 1 + while bi < lb and not b[bi].isalnum(): bi += 1 + aj = ai + bj = bi + if a[aj].isdigit(): + while aj < la and a[aj].isdigit(): aj += 1 + while bj < lb and b[bj].isdigit(): bj += 1 + isnum = 1 + else: + while aj < la and a[aj].isalpha(): aj += 1 + while bj < lb and b[bj].isalpha(): bj += 1 + isnum = 0 + if aj == ai or bj == bi: + return -1 + if isnum: + while ai < la and a[ai] == '0': ai += 1 + while bi < lb and b[bi] == '0': bi += 1 + if aj-ai > bj-bi: return 1 + if bj-bi > aj-ai: return -1 + rc = cmp(a[ai:aj], b[bi:bj]) + if rc: + return rc + ai = aj + bi = bj + if ai == la and bi == lb: + return 0 + if ai == la: + return -1 + else: + return 1 + +# vim:ts=4:sw=4 -- cgit v1.2.1