diff options
author | Dan McGee <dan@archlinux.org> | 2012-04-07 21:39:01 +0200 |
---|---|---|
committer | Dan McGee <dan@archlinux.org> | 2012-04-07 21:54:52 +0200 |
commit | b5ab5b1e218219b09857b06f88e522bccb4b5600 (patch) | |
tree | f13a9acdad6c46ccf314f2f36870220bd5caa821 /packages/views | |
parent | 1a2f117037fd8b01ec1e1e3cce5186d7bfac1a78 (diff) | |
download | archweb-b5ab5b1e218219b09857b06f88e522bccb4b5600.tar.gz archweb-b5ab5b1e218219b09857b06f88e522bccb4b5600.tar.xz |
Choose an up-to-date mirror for download URLs
Given that we collect a lot of mirror status data, we can utilize it to
ensure the download link on the website actually works and newly-added
packages have actually been mirrored out. Add a method that attempts to
use the mirror status data to determine a mirror we should redirect our
download requests to. This can change on a regular basis, and falls back
to the old method if no mirror status data is available.
Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'packages/views')
-rw-r--r-- | packages/views/__init__.py | 13 |
1 files changed, 4 insertions, 9 deletions
diff --git a/packages/views/__init__.py b/packages/views/__init__.py index 2798fff..abc86d7 100644 --- a/packages/views/__init__.py +++ b/packages/views/__init__.py @@ -14,6 +14,7 @@ from django.views.generic.simple import direct_to_template from main.models import Package, PackageFile, PackageDepend, Arch, Repo from mirrors.models import MirrorUrl +from mirrors.utils import get_mirror_url_for_download from ..models import (PackageRelation, PackageGroup, License, Conflict, Provision, Replacement) from ..utils import (get_group_info, get_differences_info, @@ -225,21 +226,15 @@ def files_json(request, name, repo, arch): def download(request, name, repo, arch): pkg = get_object_or_404(Package, pkgname=name, repo__name__iexact=repo, arch__name=arch) - mirror_urls = MirrorUrl.objects.filter( - mirror__public=True, mirror__active=True, - protocol__protocol__iexact='HTTP') - # look first for an 'Any' URL, then fall back to any HTTP URL - filtered_urls = mirror_urls.filter(mirror__country='Any')[:1] - if not filtered_urls: - filtered_urls = mirror_urls[:1] - if not filtered_urls: + url = get_mirror_url_for_download() + if not url: raise Http404 arch = pkg.arch.name if pkg.arch.agnostic: # grab the first non-any arch to fake the download path arch = Arch.objects.exclude(agnostic=True)[0].name values = { - 'host': filtered_urls[0].url, + 'host': url.url, 'arch': arch, 'repo': pkg.repo.name.lower(), 'file': pkg.filename, |