summaryrefslogtreecommitdiffstats
path: root/BuildManager/rpmver.py
diff options
context:
space:
mode:
authorBogdano Arendartchuk <bogdano@mandriva.org>2007-05-07 21:51:40 +0000
committerBogdano Arendartchuk <bogdano@mandriva.org>2007-05-07 21:51:40 +0000
commit11e2e30360a24bcc22ca4231fca495e5d846abb5 (patch)
tree9bf91715b22e91a7b739c72a08f6a3f4395c1c25 /BuildManager/rpmver.py
downloadbm-11e2e30360a24bcc22ca4231fca495e5d846abb5.tar
bm-11e2e30360a24bcc22ca4231fca495e5d846abb5.tar.gz
bm-11e2e30360a24bcc22ca4231fca495e5d846abb5.tar.bz2
bm-11e2e30360a24bcc22ca4231fca495e5d846abb5.tar.xz
bm-11e2e30360a24bcc22ca4231fca495e5d846abb5.zip
Imported bm-2.1 from2.1
svn+ssh://svn.mandriva.com/svn/packages/cooker/bm/current/SOURCES/bm-2.1.tar.bz2 at r24959.
Diffstat (limited to 'BuildManager/rpmver.py')
-rw-r--r--BuildManager/rpmver.py62
1 files changed, 62 insertions, 0 deletions
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