mirror of
https://pagure.io/fedora-infra/ansible.git
synced 2026-03-20 03:57:02 +08:00
updates+uptimes: Use hacky verscmp().
Signed-off-by: James Antill <james@and.org>
This commit is contained in:
@@ -14,6 +14,7 @@ import sys
|
||||
import argparse
|
||||
import fnmatch
|
||||
import locale
|
||||
import re
|
||||
import shutil
|
||||
import time
|
||||
|
||||
@@ -49,6 +50,9 @@ conf_term_keyword = 'underline'
|
||||
conf_term_time = 'underline'
|
||||
conf_term_title = 'italic'
|
||||
|
||||
# Use version cmp() for hostnames.
|
||||
conf_verscmp = True
|
||||
|
||||
# Use _ instead of , for number seperator.
|
||||
conf_num_sep_ = False
|
||||
|
||||
@@ -185,6 +189,41 @@ def _user_conf_line(line):
|
||||
print(" Error: Configuration ", key,'bad op', file=sys.stderr)
|
||||
return
|
||||
|
||||
# This isn't fast but it's SMALL:
|
||||
# Sort as: ABC1, ABC2, ABC10b, ...
|
||||
def verscmp(x, y):
|
||||
if not conf_verscmp:
|
||||
if x == y:
|
||||
return 0
|
||||
if x > y:
|
||||
return 1
|
||||
return -1
|
||||
|
||||
xc = re.split(r'(\d+|\W+)', x)
|
||||
yc = re.split(r'(\d+|\W+)', y)
|
||||
while xc and yc:
|
||||
if xc[0] == yc[0]:
|
||||
xc.pop(0)
|
||||
yc.pop(0)
|
||||
continue
|
||||
|
||||
if xc[0].isnumeric():
|
||||
if not yc[0].isnumeric():
|
||||
return 1
|
||||
nx = int(xc[0])
|
||||
ny = int(yc[0])
|
||||
if nx != ny: # don't make 0 == 00 ... we aren't rpm.
|
||||
return nx - ny
|
||||
elif yc[0].isnumeric():
|
||||
return -1
|
||||
|
||||
# Neither numeric, but also 0 == 00 BS
|
||||
if xc[0] > yc[0]:
|
||||
return 1
|
||||
return -1
|
||||
return len(xc) - len(yc)
|
||||
|
||||
|
||||
# Have nice "plain" numbers...
|
||||
def _ui_int(num):
|
||||
if conf_num_sep_:
|
||||
@@ -422,9 +461,10 @@ class Host():
|
||||
return True
|
||||
|
||||
def __gt__(self, other):
|
||||
if self.name > other.name:
|
||||
ret = verscmp(self.name, other.name)
|
||||
if ret > 0:
|
||||
return True
|
||||
if self.name != other.name:
|
||||
if ret < 0:
|
||||
return False
|
||||
|
||||
if self.rpms > other.rpms:
|
||||
|
||||
Reference in New Issue
Block a user