summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2012-05-02 19:23:21 +0200
committerDan McGee <dan@archlinux.org>2012-05-02 19:23:21 +0200
commitd2d0895f13835569ff25a3161ddb94cd655dfd4f (patch)
treef50d51b7495c08eb7e365cd44126e54e325ce35e
parent768bc688aab844cf9fdf9809b9381aaf0042f2fc (diff)
downloadarchweb-d2d0895f13835569ff25a3161ddb94cd655dfd4f.tar.gz
archweb-d2d0895f13835569ff25a3161ddb94cd655dfd4f.tar.xz
Allow mirrorlist generator pattern to match any protocol
Add a helper method that checks if we know about the protocol; if so, we can spit out a URL for it. This allows (if you are insane) generation of an rsync mirrorlist, for instance. Signed-off-by: Dan McGee <dan@archlinux.org>
-rw-r--r--mirrors/urls_mirrorlist.py5
-rw-r--r--mirrors/views.py18
2 files changed, 14 insertions, 9 deletions
diff --git a/mirrors/urls_mirrorlist.py b/mirrors/urls_mirrorlist.py
index e0f44c7..1444eca 100644
--- a/mirrors/urls_mirrorlist.py
+++ b/mirrors/urls_mirrorlist.py
@@ -3,10 +3,7 @@ from django.conf.urls import patterns
urlpatterns = patterns('mirrors.views',
(r'^$', 'generate_mirrorlist', {}, 'mirrorlist'),
(r'^all/$', 'find_mirrors', {'countries': ['all']}),
- (r'^all/ftp/$', 'find_mirrors',
- {'countries': ['all'], 'protocols': ['ftp']}),
- (r'^all/http/$', 'find_mirrors',
- {'countries': ['all'], 'protocols': ['http']}),
+ (r'^all/(?P<protocol>[A-z]+)/$', 'find_mirrors_simple')
)
# vim: set ts=4 sw=4 et:
diff --git a/mirrors/views.py b/mirrors/views.py
index c52656f..6f37ace 100644
--- a/mirrors/views.py
+++ b/mirrors/views.py
@@ -82,12 +82,15 @@ def generate_mirrorlist(request):
def find_mirrors(request, countries=None, protocols=None, use_status=False,
ipv4_supported=True, ipv6_supported=True):
if not protocols:
- protocols = MirrorProtocol.objects.filter(
- is_download=True).values_list('protocol', flat=True)
+ protocols = MirrorProtocol.objects.filter(is_download=True)
+ elif hasattr(protocols, 'model') and protocols.model == MirrorProtocol:
+ # we already have a queryset, no need to query again
+ pass
+ else:
+ protocols = MirrorProtocol.objects.filter(protocol__in=protocols)
qset = MirrorUrl.objects.select_related().filter(
- protocol__protocol__in=protocols,
- mirror__public=True, mirror__active=True,
- )
+ protocol__in=protocols,
+ mirror__public=True, mirror__active=True)
if countries and 'all' not in countries:
qset = qset.filter(Q(country__in=countries) |
Q(mirror__country__in=countries))
@@ -124,6 +127,11 @@ def find_mirrors(request, countries=None, protocols=None, use_status=False,
mimetype='text/plain')
+def find_mirrors_simple(request, protocol):
+ proto = get_object_or_404(MirrorProtocol, protocol=protocol)
+ return find_mirrors(request, protocols=[proto])
+
+
def mirrors(request):
mirror_list = Mirror.objects.select_related().order_by('tier', 'country')
if not request.user.is_authenticated():