/download changes:

- Display mirror domain instead of an arbitrary index (which could change)
- Fix showing 404 page for non-existent mirror redirection links
- Move default mirror definition into downloads.py for easy changing
This commit is contained in:
str4d
2013-07-03 11:54:53 +00:00
parent 0d52f8a836
commit 3a952e3222
6 changed files with 41 additions and 35 deletions

View File

@@ -1,4 +1,4 @@
from flask import redirect, render_template
from flask import abort, redirect, render_template
try:
import json
except ImportError:
@@ -7,6 +7,12 @@ from random import randint
from i2p2www import CURRENT_I2P_VERSION, MIRRORS_FILE
DEFAULT_MIRROR = {
'protocol': 'https',
'domain': 'i2p.googlecode.com',
'org': 'Google Code',
}
###################
# Download handlers
@@ -23,39 +29,36 @@ def read_mirrors():
obj=json.loads(line)
except ValueError:
continue
if 'protocol' not in obj:
if 'protocol' not in obj or 'domain' not in obj or 'path' not in obj:
continue
protocol=obj['protocol']
domain=obj['domain']
path=obj['path']
obj['url']='%s://%s%s' % (protocol, domain, path)
if protocol not in ret:
ret[protocol]=[]
ret[protocol].append(obj)
ret[protocol]={}
ret[protocol][domain]=obj
return ret
# List of downloads
def downloads_list():
# TODO: read mirror list or list of available files
return render_template('downloads/list.html')
return render_template('downloads/list.html', def_mirror=DEFAULT_MIRROR)
# Specific file downloader
def downloads_select(version, file):
if (file == 'debian'):
return render_template('downloads/debian.html', file=file)
mirrors=read_mirrors()
data = {
'version': version,
'file': file,
}
obj=[]
for protocol in mirrors.keys():
a={}
a['name']=protocol
a['mirrors']=mirrors[protocol]
for mirror in a['mirrors']:
mirror['url']=mirror['url'] % data
obj.append(a)
return render_template('downloads/select.html', mirrors=obj, version=version, file=file)
def downloads_redirect(version, protocol, file, mirror):
def downloads_redirect(version, protocol, domain, file):
mirrors=read_mirrors()
if not protocol in mirrors:
abort(404)
@@ -64,6 +67,8 @@ def downloads_redirect(version, protocol, file, mirror):
'version': version,
'file': file,
}
if mirror:
return redirect(mirrors[mirror-1]['url'] % data)
if domain:
if not domain in mirrors:
abort(404)
return redirect(mirrors[domain]['url'] % data)
return redirect(mirrors[randint(0, len(mirrors) - 1)]['url'] % data)

View File

@@ -23,12 +23,12 @@ or type <tt>java -version</tt> at your command prompt.
<div class="package">
<h1>Windows</h1>
<div class="file">
<a href="{{ url_for('downloads_redirect', version=ver(), protocol='https', file=ver('i2pinstall_%s_windows.exe'), mirror=1) }}">i2pinstall_{{ ver() }}_windows.exe</a> (Google Code)
<a href="{{ url_for('downloads_redirect', version=ver(), protocol=def_mirror.protocol, domain=def_mirror.domain, file=ver('i2pinstall_%s_windows.exe')) }}">i2pinstall_{{ ver() }}_windows.exe</a> ({{ def_mirror.org }})
(<a href="{{ get_url('downloads_select', version=ver(), file=ver('i2pinstall_%s_windows.exe')) }}">{{ _('select alternate link') }}</a>)
<div class="sig">
(SHA256
<code>bf7d11f0a36acff9cd51ad3ef89d66975b0b0de344ca72719a5576159ec965d1</code>
<a href="{{ url_for('downloads_redirect', version=ver(), protocol='https', file=ver('i2pinstall_%s_windows.exe.sig'), mirror=1) }}">sig</a>)
<a href="{{ url_for('downloads_redirect', version=ver(), protocol=def_mirror.protocol, domain=def_mirror.domain, file=ver('i2pinstall_%s_windows.exe.sig')) }}">sig</a>)
</div>
</div>
<div class="details">
@@ -41,12 +41,12 @@ or type <tt>java -version</tt> at your command prompt.
<div class="package">
<h1>Mac OS X</h1>
<div class="file">
<a href="{{ url_for('downloads_redirect', version=ver(), protocol='https', file=ver('i2pinstall_%s.jar'), mirror=1) }}">i2pinstall_{{ ver() }}.jar</a> (Google Code)
<a href="{{ url_for('downloads_redirect', version=ver(), protocol=def_mirror.protocol, domain=def_mirror.domain, file=ver('i2pinstall_%s.jar')) }}">i2pinstall_{{ ver() }}.jar</a> ({{ def_mirror.org }})
(<a href="{{ get_url('downloads_select', version=ver(), file=ver('i2pinstall_%s.jar')) }}">{{ _('select alternate link') }}</a>)
<div class="sig">
(SHA256
<code>2dd5b67920723dd94202a408de31671b1e9543fcd5611bbe79385cc14f93b371</code>
<a href="{{ url_for('downloads_redirect', version=ver(), protocol='https', file=ver('i2pinstall_%s.jar.sig'), mirror=1) }}">sig</a>)
<a href="{{ url_for('downloads_redirect', version=ver(), protocol=def_mirror.protocol, domain=def_mirror.domain, file=ver('i2pinstall_%s.jar.sig')) }}">sig</a>)
</div>
</div>
<div class="details">
@@ -69,12 +69,12 @@ or type <tt>java -version</tt> at your command prompt.
<div class="package">
<h1>GNU/Linux / BSD / Solaris</h1>
<div class="file">
<a href="{{ url_for('downloads_redirect', version=ver(), protocol='https', file=ver('i2pinstall_%s.jar'), mirror=1) }}">i2pinstall_{{ ver() }}.jar</a> (Google Code)
<a href="{{ url_for('downloads_redirect', version=ver(), protocol=def_mirror.protocol, domain=def_mirror.domain, file=ver('i2pinstall_%s.jar')) }}">i2pinstall_{{ ver() }}.jar</a> ({{ def_mirror.org }})
(<a href="{{ get_url('downloads_select', version=ver(), file=ver('i2pinstall_%s.jar')) }}">{{ _('select alternate link') }}</a>)
<div class="sig">
(SHA256
<code>2dd5b67920723dd94202a408de31671b1e9543fcd5611bbe79385cc14f93b371</code>
<a href="{{ url_for('downloads_redirect', version=ver(), protocol='https', file=ver('i2pinstall_%s.jar.sig'), mirror=1) }}">sig</a>)
<a href="{{ url_for('downloads_redirect', version=ver(), protocol=def_mirror.protocol, domain=def_mirror.domain, file=ver('i2pinstall_%s.jar.sig')) }}">sig</a>)
</div>
</div>
<div class="details">
@@ -131,12 +131,12 @@ or type <tt>java -version</tt> at your command prompt.
<div class="package">
<h1>{{ _('Source package') }}</h1>
<div class="file">
<a href="{{ url_for('downloads_redirect', version=ver(), protocol='https', file=ver('i2psource_%s.tar.bz2'), mirror=1) }}">i2psource_{{ ver() }}.tar.bz2</a> (Google Code)
<a href="{{ url_for('downloads_redirect', version=ver(), protocol=def_mirror.protocol, domain=def_mirror.domain, file=ver('i2psource_%s.tar.bz2')) }}">i2psource_{{ ver() }}.tar.bz2</a> ({{ def_mirror.org }})
(<a href="{{ get_url('downloads_select', version=ver(), file=ver('i2psource_%s.tar.bz2')) }}">{{ _('select alternate link') }}</a>)
<div class="sig">
(SHA256
<code>fd2aa881d68b3164c43de9d91dcb04a93a36228d416582ada14ae40031436d18</code>
<a href="{{ url_for('downloads_redirect', version=ver(), protocol='https', file=ver('i2psource_%s.tar.bz2.sig'), mirror=1) }}">sig</a>)
<a href="{{ url_for('downloads_redirect', version=ver(), protocol=def_mirror.protocol, domain=def_mirror.domain, file=ver('i2psource_%s.tar.bz2.sig')) }}">sig</a>)
</div>
</div>
<div class="details">
@@ -261,12 +261,12 @@ receive the release.
<div class="package">
<h1>{{ _('Manual updates') }}</h1>
<div class="file">
<a href="{{ url_for('downloads_redirect', version=ver(), protocol='https', file=ver('i2pupdate_%s.zip'), mirror=1) }}">i2pupdate_{{ ver() }}.zip</a> (Google Code)
<a href="{{ url_for('downloads_redirect', version=ver(), protocol=def_mirror.protocol, domain=def_mirror.domain, file=ver('i2pupdate_%s.zip')) }}">i2pupdate_{{ ver() }}.zip</a> ({{ def_mirror.org }})
(<a href="{{ get_url('downloads_select', version=ver(), file=ver('i2pupdate_%s.zip')) }}">{{ _('select alternate link') }}</a>)
<div class="sig">
(SHA256
<code>f322de7a9e3e89411d072d983a6577494981da488bb08f839c521ed340d77b92</code>
<a href="{{ url_for('downloads_redirect', version=ver(), protocol='https', file=ver('i2pupdate_%s.zip.sig'), mirror=1) }}">sig</a>)
<a href="{{ url_for('downloads_redirect', version=ver(), protocol=def_mirror.protocol, domain=def_mirror.domain, file=ver('i2pupdate_%s.zip.sig')) }}">sig</a>)
</div>
</div>
<div class="details">

View File

@@ -1,7 +1,7 @@
{"url": "http://i2p.googlecode.com/files/%(file)s", "org": "Google Code", "org_url": "http://code.google.com", "protocol": "http", "country": "us"}
{"url": "https://i2p.googlecode.com/files/%(file)s", "org": "Google Code", "org_url": "https://code.google.com", "protocol": "https", "country": "us"}
{"url": "https://launchpad.net/i2p/trunk/%(version)s/+download/%(file)s", "org": "Launchpad", "org_url": "https://launchpad.net", "protocol": "https", "country": "us"}
{"url": "http://golden.mtveurope.org/~yang/i2p_mirror/%(file)s", "org": "VServer.si", "org_url": "http://www.vserver.si", "protocol": "http", "country": "lu"}
{"url": "http://a.mirror.geti2p.net/releases/current/%(file)s", "org": "welterde", "protocol": "http", "country": "de"}
{"url": "http://download.i2p2.no/releases/current/%(file)s", "org": "meeh", "protocol": "http", "country": "no"}
{"url": "https://googledrive.com/host/0B4jHEq5G7_EPWV9UeERwdGplZXc/%(version)s/%(file)s", "org": "Google Drive", "protocol": "https", "country": "us"}
{"protocol": "http", "domain": "i2p.googlecode.com", "path": "/files/%(file)s", "org": "Google Code", "org_url": "http://code.google.com", "country": "us"}
{"protocol": "https", "domain": "i2p.googlecode.com", "path": "/files/%(file)s", "org": "Google Code", "org_url": "https://code.google.com", "country": "us"}
{"protocol": "https", "domain": "launchpad.net", "path": "/i2p/trunk/%(version)s/+download/%(file)s", "org": "Launchpad", "org_url": "https://launchpad.net", "country": "us"}
{"protocol": "http", "domain": "golden.mtveurope.org", "path": "/~yang/i2p_mirror/%(file)s", "org": "VServer.si", "org_url": "http://www.vserver.si", "country": "lu"}
{"protocol": "http", "domain": "a.mirror.geti2p.net", "path": "/releases/current/%(file)s", "org": "welterde", "country": "de"}
{"protocol": "http", "domain": "download.i2p2.no", "path": "/releases/current/%(file)s", "org": "meeh", "country": "no"}
{"protocol": "https", "domain": "googledrive.com", "path": "/host/0B4jHEq5G7_EPWV9UeERwdGplZXc/%(version)s/%(file)s", "org": "Google Drive", "country": "us"}

View File

@@ -8,8 +8,8 @@
<h3>{{ protocol.name | upper }}</h3>
<ul>
<li><a href="{{ url_for('downloads_redirect', version=version, protocol=protocol.name, file=file) }}">{{ _('Any mirror') }}</a></li>
{% for mirror in protocol.mirrors -%}
<li><img src="{{ url_for('static', filename='images/flags/'+mirror.country+'.png') }}" />&nbsp;{% if mirror.org_url %}<a href="{{ mirror.org_url }}">{% endif %}{{ mirror.org }}{% if mirror.org_url %}</a>{% endif %} <a href="{{ url_for('downloads_redirect', version=version, protocol=protocol.name, file=file, mirror=loop.index) }}">[{{ _('Download') }}]</a> <a href="{{ url_for('downloads_redirect', version=version, protocol=protocol.name, file=file+'.sig', mirror=loop.index) }}">[sig]</a></li>
{% for domain, mirror in protocol.mirrors.items() -%}
<li><img src="{{ url_for('static', filename='images/flags/'+mirror.country+'.png') }}" />&nbsp;{% if mirror.org_url %}<a href="{{ mirror.org_url }}">{% endif %}{{ mirror.org }}{% if mirror.org_url %}</a>{% endif %} <a href="{{ url_for('downloads_redirect', version=version, protocol=protocol.name, domain=domain, file=file) }}">[{{ _('Download') }}]</a> <a href="{{ url_for('downloads_redirect', version=version, protocol=protocol.name, domain=domain, file=file+'.sig') }}">[sig]</a></li>
{%- endfor %}
</ul>
</div>

View File

@@ -7,6 +7,7 @@
{%- elif request.endpoint == 'blog_post' -%}{{ url_for('blog_post', lang=lang, slug=slug) }}
{%- elif request.endpoint == 'meetings_show' -%}{{ url_for('meetings_show', lang=lang, id=id) }}
{%- elif request.endpoint == 'downloads_select' -%}{{ url_for('downloads_select', lang=lang, version=version, file=file) }}
{%- elif request.endpoint == 'downloads_redirect' -%}{{ url_for('site_show', lang=lang) }}
{%- elif request.endpoint -%}{{ url_for(request.endpoint, lang=lang) }}
{%- else -%}{{ url_for('site_show', lang=lang) }}
{%- endif -%}

View File

@@ -56,8 +56,8 @@ url('/<lang:lang>/feed/meetings/atom', 'meetings.views.meetings_atom')
url('/<lang:lang>/download', 'downloads.downloads_list')
url('/<lang:lang>/download/<string:version>/<path:file>', 'downloads.downloads_select')
url('/download/<string:version>/<string:protocol>/any/<path:file>', 'downloads.downloads_redirect', defaults={'mirror': None})
url('/download/<string:version>/<string:protocol>/<int:mirror>/<path:file>', 'downloads.downloads_redirect')
url('/download/<string:version>/<string:protocol>/any/<path:file>', 'downloads.downloads_redirect', defaults={'domain': None})
url('/download/<string:version>/<string:protocol>/<string:domain>/<path:file>', 'downloads.downloads_redirect')
url('/meeting<int:id>', 'legacy.legacy_meeting')
url('/meeting<int:id>.html', 'legacy.legacy_meeting')