Attempt to fix version sorting in ftp browser
authorMagnus Hagander <magnus@hagander.net>
Fri, 13 Oct 2017 13:56:25 +0000 (15:56 +0200)
committerMagnus Hagander <magnus@hagander.net>
Fri, 13 Oct 2017 13:56:25 +0000 (15:56 +0200)
There was already an ugly hack to handle this, so make it a bit uglier
with even more hardcoded assumptions. Seems to be working for the site
as it is now, but may definitely need further ugly hacks in the future.

pgweb/util/misc.py

index 4b3e0728e53f8e449d5d69aa595491801e80366d..3f436c850bc5f5309231c5067d7e49499beae8c9 100644 (file)
@@ -40,14 +40,25 @@ def varnish_purge(url):
 def version_sort(l):
        """
        map a directory name to a format that will show up sensibly in an ascii sort
+       We specifically detect entries that look like versions. Weird things may happen
+       if there is a mix of versions and non-versions in the same directory, but we
+       generally don't have that.
        """
        mkey = l['link']
-       m = re.match('v([0-9]+)\.([0-9]+)\.([0-9]+)$',l['url'])
+       m = re.match('v?([0-9]+)\.([0-9]+)\.([0-9]+)$',l['url'])
        if m:
                mkey = m.group(1) + '%02d' % int(m.group(2)) + '%02d' % int(m.group(3));
-       m = re.match('v([0-9]+)\.([0-9]+)$',l['url'])
+       m = re.match('v?([0-9]+)\.([0-9]+)$',l['url'])
        if m:
                mkey = m.group(1) + '%02d' % int(m.group(2));
+               # SOOO ugly. But if it's v10 and up, just prefix it to get it higher
+               if int(m.group(1)) >= 10:
+                       mkey = 'a' + mkey
+       m = re.match('v?([0-9]+)$', l['url'])
+       if m:
+               # This can only happen on 10+, so...
+               mkey = 'a' + m.group(1) + '0'
+
        return mkey
 
 def generate_random_token():