Module: check_mk
Branch: master
Commit: ad112795b3711851c524a9514baefe24c5788591
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=ad112795b37118…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Tue Sep 20 09:15:52 2016 +0200
3885 FIX Fixed sorting of version in werk list (1.2.8p10 and 1.2.8p11 were not listed on
top)
---
.werks/3885 | 10 ++++++++++
ChangeLog | 1 +
modules/check_mk_base.py | 1 +
web/htdocs/werks.py | 49 +++++++++++++++++++++++++++++++++++++++++++++++-
4 files changed, 60 insertions(+), 1 deletion(-)
diff --git a/.werks/3885 b/.werks/3885
new file mode 100644
index 0000000..7f11a33
--- /dev/null
+++ b/.werks/3885
@@ -0,0 +1,10 @@
+Title: Fixed sorting of version in werk list (1.2.8p10 and 1.2.8p11 were not listed on
top)
+Level: 1
+Component: multisite
+Class: fix
+Compatible: compat
+State: unknown
+Version: 1.4.0i1
+Date: 1474355728
+
+
diff --git a/ChangeLog b/ChangeLog
index 8745e77..acdae50 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -505,6 +505,7 @@
* 3850 FIX: Fixed JS error when quicksearch snapin not in sidebar
* 3871 FIX: stale services view: excluded services in downtime per default
* 3874 FIX: fixed graphs displaying wrong labels
+ * 3885 FIX: Fixed sorting of version in werk list (1.2.8p10 and 1.2.8p11 were not
listed on top)
WATO:
* 3244 WATO BI Module: swap order of aggregation function and child node
selection...
diff --git a/modules/check_mk_base.py b/modules/check_mk_base.py
index 1faaf69..192e97c 100644
--- a/modules/check_mk_base.py
+++ b/modules/check_mk_base.py
@@ -1362,6 +1362,7 @@ def branch_of_daily_build(v):
# 1.2.4b1 -> 01020420100
# 1.2.3i1p1 -> 01020310101
# 1.2.3i1 -> 01020310100
+# TODO: Copied to werks.py - find location for common code.
def parse_check_mk_version(v):
def extract_number(s):
number = ''
diff --git a/web/htdocs/werks.py b/web/htdocs/werks.py
index 31ff1f0..8d58e75 100644
--- a/web/htdocs/werks.py
+++ b/web/htdocs/werks.py
@@ -606,6 +606,53 @@ def werks_sorted_by_version(werks):
if lhs["version"] == rhs["version"]:
return cmp(lhs["date"], rhs["date"])
else:
- return cmp(lhs["version"], rhs["version"])
+ return cmp(parse_check_mk_version(lhs["version"]),
+ parse_check_mk_version(rhs["version"]))
return sorted(werks, cmp=by_version, reverse=True)
+
+
+# Parses versions of Check_MK and converts them into comparable integers.
+# This does not handle daily build numbers, only official release numbers.
+# 1.2.4p1 -> 01020450001
+# 1.2.4 -> 01020450000
+# 1.2.4b1 -> 01020420100
+# 1.2.3i1p1 -> 01020310101
+# 1.2.3i1 -> 01020310100
+# TODO: Copied from check_mk_base.py - find location for common code.
+def parse_check_mk_version(v):
+ def extract_number(s):
+ number = ''
+ for i, c in enumerate(s):
+ try:
+ int(c)
+ number += c
+ except ValueError:
+ s = s[i:]
+ return number and int(number) or 0, s
+ return number and int(number) or 0, ''
+
+ parts = v.split('.')
+ while len(parts) < 3:
+ parts.append("0")
+
+ major, minor, rest = parts
+ sub, rest = extract_number(rest)
+
+ if not rest:
+ val = 50000
+ elif rest[0] == 'p':
+ num, rest = extract_number(rest[1:])
+ val = 50000 + num
+ elif rest[0] == 'i':
+ num, rest = extract_number(rest[1:])
+ val = 10000 + num*100
+
+ if rest and rest[0] == 'p':
+ num, rest = extract_number(rest[1:])
+ val += num
+ elif rest[0] == 'b':
+ num, rest = extract_number(rest[1:])
+ val = 20000 + num*100
+
+ return int('%02d%02d%02d%05d' % (int(major), int(minor), sub, val))