Attempt to fix version sorting in ftp browser

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.
This commit is contained in:
Magnus Hagander
2017-10-13 15:56:25 +02:00
parent 022dd26283
commit c06ece5dd8

View 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():