From 05316e32921cb9b529adfbbd0389ac5f901e204a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Fri, 28 Aug 2015 18:28:39 -0700 Subject: [PATCH] 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. --- fdroidserver/common.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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)