From: Daniel Martí Date: Sat, 29 Aug 2015 01:28:39 +0000 (-0700) Subject: stats: write known apks in natural order X-Git-Tag: 0.5.0~157 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=05316e32921cb9b529adfbbd0389ac5f901e204a;p=fdroidserver.git stats: write known apks in natural order By using natural instead of alphabetical sorting, we support sorting by vercodes properly and thus app versions show in the correct order. --- diff --git a/fdroidserver/common.py b/fdroidserver/common.py index f546020a..5a983f5c 100644 --- a/fdroidserver/common.py +++ b/fdroidserver/common.py @@ -1654,6 +1654,10 @@ def scan_source(build_dir, root_dir, thisbuild): return count +def natural_key(s): + return [int(sp) if sp.isdigit() else sp for sp in re.split(r'(\d+)', s)] + + class KnownApks: def __init__(self): @@ -1684,7 +1688,7 @@ class KnownApks: lst.append(line) with open(self.path, 'w') as f: - for line in sorted(lst): + for line in sorted(lst, key=natural_key): f.write(line + '\n') # Record an apk (if it's new, otherwise does nothing)