From 1179ec9d96b3ed218e02972e79b3c7b39fc47835 Mon Sep 17 00:00:00 2001 From: James Antill Date: Thu, 6 Nov 2025 18:08:18 -0500 Subject: [PATCH] updates+uptimes: Use verscmp() for osinfo in stats. Signed-off-by: James Antill --- files/scripts/updates-uptime-cmd.py | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/files/scripts/updates-uptime-cmd.py b/files/scripts/updates-uptime-cmd.py index 9584397731..e481c79d00 100755 --- a/files/scripts/updates-uptime-cmd.py +++ b/files/scripts/updates-uptime-cmd.py @@ -224,6 +224,31 @@ def verscmp(x, y): return len(xc) - len(yc) +class VerscmpString(): + __slots__ = ['s',] + def __init__(self, s): + self.s = s + + def __str__(self): + return self.s + + def __eq__(self, other): + return self.s == other.s + + def __gt__(self, other): + ret = verscmp(self.s, other.s) + if ret > 0: + return True + if False and ret < 0: + return False + return False + +# Given a list of strings, sort them using verscmp() +def _verscmp_strings(xs): + for ret in sorted(VerscmpString(x) for x in xs): + yield ret.s + + # Have nice "plain" numbers... def _ui_int(num): if conf_num_sep_: @@ -1253,7 +1278,7 @@ def _cmd_stats(args): max_nhosts_lvl_2 = 0 max_update_lvl_2 = 0 max_uptime_lvl_2 = 0 - for osi in sorted(osdata['hosts']): + for osi in _verscmp_strings(osdata['hosts']): if '/' not in osi: max_nhosts_lvl_1 = max(max_nhosts_lvl_1, osdata['hosts'][osi]) supd = osdata['updates'][osi] / osdata['hosts'][osi] @@ -1301,7 +1326,7 @@ def _cmd_stats(args): suf = _ui_t_high(suf) return uiosi, uinhosts, uiupdates, uiuptimes, uinpdates, uinptimes, suf - for osi in sorted(osdata['hosts']): + for osi in _verscmp_strings(osdata['hosts']): if '/' not in osi: if len(osdata['vers'][osi]) == 1: subprefix = ''