From 6243f7ba662b39c25835c65b6641531e8c66c95f Mon Sep 17 00:00:00 2001 From: Ismael Carnales Date: Sat, 31 Oct 2009 13:22:09 -0200 Subject: added mirrors app from archweb_pub --- mirrors/__init__.py | 0 mirrors/views.py | 56 ++++++++++++++++++++++++++++++++++++++++ settings.py | 1 + templates/mirrors/index.html | 25 ++++++++++++++++++ templates/mirrors/mirrorlist.txt | 13 ++++++++++ urls.py | 6 +++++ 6 files changed, 101 insertions(+) create mode 100644 mirrors/__init__.py create mode 100644 mirrors/views.py create mode 100644 templates/mirrors/index.html create mode 100644 templates/mirrors/mirrorlist.txt diff --git a/mirrors/__init__.py b/mirrors/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/mirrors/views.py b/mirrors/views.py new file mode 100644 index 0000000..5ad522b --- /dev/null +++ b/mirrors/views.py @@ -0,0 +1,56 @@ +from django import forms +from django.core.urlresolvers import reverse +from django.db.models import Q +from django.http import HttpResponseRedirect +from django.shortcuts import get_object_or_404, render_to_response +from archweb.main.models import Arch, Mirror, MirrorUrl +from archweb.main.utils import make_choice + +class MirrorlistForm(forms.Form): + arch = forms.ChoiceField(required=True) + country = forms.ChoiceField(required=False) + + def __init__(self, *args, **kwargs): + super(MirrorlistForm, self).__init__(*args, **kwargs) + arches = Arch.objects.exclude(name__iexact='any').order_by('name') + mirrors = Mirror.objects.values_list( + 'country', flat=True).distinct().order_by('country') + self.fields['arch'].choices = make_choice( + [arch.name for arch in arches]) + self.fields['country'].choices = [('all', 'All')] + make_choice( + [mirror for mirror in mirrors]) + + +def choose(request): + if request.POST: + form = MirrorlistForm(data=request.POST) + if form.is_valid(): + arch = form.cleaned_data['arch'] + country = form.cleaned_data['country'] + return HttpResponseRedirect(reverse(generate, + kwargs = {'arch' : arch, 'country' : country })) + else: + form = MirrorlistForm() + return render_to_response('mirrors/index.html', + {'mirrorlist_form': form}) + +def generate(request, arch='i686', country=None): + # do a quick sanity check on the architecture + archobj = get_object_or_404(Arch, name=arch) + qset = MirrorUrl.objects.filter( + Q(protocol__protocol__iexact='HTTP') | + Q(protocol__protocol__iexact='FTP'), + mirror__public=True, mirror__active=True, mirror__isos=True + ) + if country and country != 'all': + qset = qset.filter(mirror__country__iexact=country) + qset = qset.order_by('mirror__country', 'mirror__name', 'url') + res = render_to_response('mirrors/mirrorlist.txt', + { + 'mirror_urls': qset, + 'arch': arch, + }, + mimetype='text/plain') + return res + +# vim: set ts=4 sw=4 et: diff --git a/settings.py b/settings.py index d97c785..6696fa5 100644 --- a/settings.py +++ b/settings.py @@ -72,6 +72,7 @@ INSTALLED_APPS = ( 'django.contrib.sitemaps', 'django.contrib.admin', 'archweb.main', # contains shared models and libs + 'archweb.mirrors', 'archweb.news', 'archweb.packages', 'archweb.todolists', diff --git a/templates/mirrors/index.html b/templates/mirrors/index.html new file mode 100644 index 0000000..73949c6 --- /dev/null +++ b/templates/mirrors/index.html @@ -0,0 +1,25 @@ +{% extends "base.html" %} +{% load package_extras %} +{% block title %}Arch Linux - Generate Mirrorlist{% endblock %} + +{% block content %} +
+

Generate Custom Mirrorlist

+
+ + + + {% td_input mirrorlist_form.arch %} + + + + {% td_input mirrorlist_form.country %} + + + + +
Architecture
Country
+
+
+{% endblock %} + diff --git a/templates/mirrors/mirrorlist.txt b/templates/mirrors/mirrorlist.txt new file mode 100644 index 0000000..891800d --- /dev/null +++ b/templates/mirrors/mirrorlist.txt @@ -0,0 +1,13 @@ +{% comment %} +Yes, ugly templates are ugly, but in order to keep line breaks where we want +them, sacrifices have to be made. If editing this template, it is easiest to +forget about where line breaks are happening until you are done getting the +content right, and then go back later to fix it all up. +{% endcomment %}{% autoescape off %}# +# Arch Linux repository mirrorlist +# Generated on {% now "Y-m-d" %} +#{% for mirror_url in mirror_urls %}{% ifchanged %} + +# {{ mirror_url.mirror.country }}{% endifchanged %} +#Server = {{ mirror_url.url}}$repo/os/{{ arch }}{% endfor %} +{% endautoescape %} diff --git a/urls.py b/urls.py index 7a870ea..ccac493 100644 --- a/urls.py +++ b/urls.py @@ -57,6 +57,12 @@ urlpatterns = patterns('', (r'^mirrors/$', 'archweb.devel.views.mirrorlist'), + (r'^mirrorlist/$', 'archweb.mirrors.views.choose'), + (r'^mirrorlist/(?P[\S]+)/(?P[A-z0-9 ]+)/$', + 'archweb.mirrors.views.generate'), + (r'^mirrorlist/(?P[\S]+)/$', + 'archweb.mirrors.views.generate'), + (r'^devel/$', 'archweb.devel.views.index'), (r'^devel/notify/$', 'archweb.devel.views.change_notify'), (r'^devel/profile/$', 'archweb.devel.views.change_profile'), -- cgit v1.2.3-24-g4f1b