summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2010-11-04 14:29:50 -0500
committerDan McGee <dan@archlinux.org>2010-11-04 14:29:50 -0500
commit3dea0da4a9b3fdb63be4e197ab49a5e1d1842398 (patch)
tree22869af46e4b4781f5ee3b666f20012c99e8c8a7
parent863d7628175fdb30d29437e81fb3332354621a43 (diff)
Ensure mirrorlist generator works if no status available
Saw this error come through on the live site today, as well as being reproducible when no mirror check runs have happened in the last 24 hours on a development machine. Let mirrors that have no available checks show up on this page, but be sorted last and show a score of unknown. Signed-off-by: Dan McGee <dan@archlinux.org>
-rw-r--r--mirrors/views.py11
1 files changed, 7 insertions, 4 deletions
diff --git a/mirrors/views.py b/mirrors/views.py
index 93007acb..fb7d3361 100644
--- a/mirrors/views.py
+++ b/mirrors/views.py
@@ -11,7 +11,6 @@ from .models import Mirror, MirrorUrl, MirrorProtocol
from .utils import get_mirror_statuses, get_mirror_errors
import datetime
-from operator import attrgetter
class MirrorlistForm(forms.Form):
country = forms.MultipleChoiceField(required=False)
@@ -77,10 +76,14 @@ def find_mirrors(request, countries=None, protocols=None, use_status=False,
scores = dict([(u.id, u.score) for u in status_info['urls']])
urls = []
for u in qset:
- u.score = scores[u.id]
- if u.score and u.score < 100.0:
+ u.score = scores.get(u.id, None)
+ # also include mirrors that don't have an up to date score
+ # (as opposed to those that have been set with no score)
+ if (u.id not in scores) or \
+ (u.score and u.score < 100.0):
urls.append(u)
- urls = sorted(urls, key=attrgetter('score'))
+ # if a url doesn't have a score, treat it as the highest possible
+ urls = sorted(urls, key=lambda x: x.score or 100.0)
template = 'mirrors/mirrorlist_status.txt'
return direct_to_template(request, template, {