Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Adds a new function to compare version strings. It's a specialized

version of strcmp().
  • Loading branch information...
commit c3382255980751a5b93bd4939385388f30604afb 1 parent 9c4ed34
alo authored committed
Showing with 46 additions and 0 deletions.
  1. +46 −0 admin/util.py
View
46 admin/util.py
@@ -154,6 +154,52 @@ def cfg_get_surrounding_repls (macro, value, n_minus=9, n_plus=9):
return replacements
+#
+# Version strings management
+#
+
+def version_to_int (v):
+ num = 0
+ tmp = v.split('.')
+
+ if len(tmp) >= 3:
+ num += int(tmp[2]) * (10**3)
+ if len(tmp) >= 2:
+ num += int(tmp[1]) * (10**6)
+ if len(tmp) >= 1:
+ num += int(tmp[0]) * (10**9)
+
+ return num
+
+def version_cmp (x, y):
+ xp = x.split('b')
+ yp = y.split('b')
+
+ if len(xp) > 1:
+ x_ver = version_to_int(xp[0])
+ x_beta = xp[1]
+ else:
+ x_ver = version_to_int(xp[0])
+ x_beta = None
+
+ if len(yp) > 1:
+ y_ver = version_to_int(yp[0])
+ y_beta = yp[1]
+ else:
+ y_ver = version_to_int(yp[0])
+ y_beta = None
+
+ if x_ver == y_ver:
+ if not x_beta and not y_beta: return 0
+ if not y_beta: return -1
+ if not x_beta: return 1
+ return cmp(int(x_beta),int(y_beta))
+
+ elif x_ver > y_ver:
+ return 1
+
+ return -1
+
#
# Paths
Please sign in to comment.
Something went wrong with that request. Please try again.