chiark / gitweb /
stats: write known apks in natural order
authorDaniel Martí <mvdan@mvdan.cc>
Sat, 29 Aug 2015 01:28:39 +0000 (18:28 -0700)
committerDaniel Martí <mvdan@mvdan.cc>
Sat, 29 Aug 2015 01:28:39 +0000 (18:28 -0700)
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

index f546020ac1c350d5472bbbede8d4c017fa75089b..5a983f5ce363893e950839a9f4ac45b412402ecf 100644 (file)
@@ -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)