Skip to content

Commit

Permalink
Adds a new function to compare version strings. It's a specialized
Browse files Browse the repository at this point in the history
version of strcmp().
  • Loading branch information
alo authored and mdavid committed Jul 5, 2010
1 parent 9c4ed34 commit c338225
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions admin/util.py
Expand Up @@ -154,6 +154,52 @@ def cfg_get_surrounding_repls (macro, value, n_minus=9, n_plus=9):


return replacements 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 # Paths
Expand Down

0 comments on commit c338225

Please sign in to comment.