summaryrefslogtreecommitdiffstats
path: root/BuildManager/rpmver.py
diff options
context:
space:
mode:
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