summaryrefslogtreecommitdiff
path: root/mirrors
diff options
context:
space:
mode:
Diffstat (limited to 'mirrors')
-rw-r--r--mirrors/management/commands/mirrorcheck.py5
-rw-r--r--mirrors/urls.py2
-rw-r--r--mirrors/urls_mirrorlist.py2
-rw-r--r--mirrors/utils.py13
4 files changed, 13 insertions, 9 deletions
diff --git a/mirrors/management/commands/mirrorcheck.py b/mirrors/management/commands/mirrorcheck.py
index 8eb8b010..c2928e67 100644
--- a/mirrors/management/commands/mirrorcheck.py
+++ b/mirrors/management/commands/mirrorcheck.py
@@ -21,9 +21,11 @@ import sys
import time
from threading import Thread
import types
+from pytz import utc
from Queue import Queue, Empty
import urllib2
+from main.utils import utc_now
from mirrors.models import MirrorUrl, MirrorLog
logging.basicConfig(
@@ -50,7 +52,7 @@ class Command(NoArgsCommand):
def check_mirror_url(mirror_url):
url = mirror_url.url + 'lastsync'
logger.info("checking URL %s", url)
- log = MirrorLog(url=mirror_url, check_time=datetime.utcnow())
+ log = MirrorLog(url=mirror_url, check_time=utc_now())
try:
start = time.time()
result = urllib2.urlopen(url, timeout=10)
@@ -61,6 +63,7 @@ def check_mirror_url(mirror_url):
parsed_time = None
try:
parsed_time = datetime.utcfromtimestamp(int(data))
+ parsed_time = parsed_time.replace(tzinfo=utc)
except ValueError:
# it is bad news to try logging the lastsync value;
# sometimes we get a crazy-encoded web page.
diff --git a/mirrors/urls.py b/mirrors/urls.py
index fed9c807..f002e9d6 100644
--- a/mirrors/urls.py
+++ b/mirrors/urls.py
@@ -1,4 +1,4 @@
-from django.conf.urls.defaults import patterns
+from django.conf.urls import patterns
urlpatterns = patterns('mirrors.views',
(r'^$', 'mirrors', {}, 'mirror-list'),
diff --git a/mirrors/urls_mirrorlist.py b/mirrors/urls_mirrorlist.py
index 70bc18d2..e0f44c78 100644
--- a/mirrors/urls_mirrorlist.py
+++ b/mirrors/urls_mirrorlist.py
@@ -1,4 +1,4 @@
-from django.conf.urls.defaults import patterns
+from django.conf.urls import patterns
urlpatterns = patterns('mirrors.views',
(r'^$', 'generate_mirrorlist', {}, 'mirrorlist'),
diff --git a/mirrors/utils.py b/mirrors/utils.py
index f05ffc77..0f8fef84 100644
--- a/mirrors/utils.py
+++ b/mirrors/utils.py
@@ -1,11 +1,12 @@
+from datetime import timedelta
+
from django.db.models import Avg, Count, Max, Min, StdDev
-from main.utils import cache_function
+from main.utils import cache_function, utc_now
from .models import MirrorLog, MirrorProtocol, MirrorUrl
-import datetime
-default_cutoff = datetime.timedelta(hours=24)
+default_cutoff = timedelta(hours=24)
def annotate_url(url, delays):
'''Given a MirrorURL object, add a few more attributes to it regarding
@@ -13,7 +14,7 @@ def annotate_url(url, delays):
url.completion_pct = float(url.success_count) / url.check_count
if url.id in delays:
url_delays = delays[url.id]
- url.delay = sum(url_delays, datetime.timedelta()) / len(url_delays)
+ url.delay = sum(url_delays, timedelta()) / len(url_delays)
hours = url.delay.days * 24.0 + url.delay.seconds / 3600.0
if url.completion_pct > 0:
@@ -28,7 +29,7 @@ def annotate_url(url, delays):
@cache_function(123)
def get_mirror_statuses(cutoff=default_cutoff):
- cutoff_time = datetime.datetime.utcnow() - cutoff
+ cutoff_time = utc_now() - cutoff
protocols = list(MirrorProtocol.objects.filter(is_download=True))
# I swear, this actually has decent performance...
urls = MirrorUrl.objects.select_related('mirror', 'protocol').filter(
@@ -82,7 +83,7 @@ def get_mirror_statuses(cutoff=default_cutoff):
@cache_function(117)
def get_mirror_errors(cutoff=default_cutoff):
- cutoff_time = datetime.datetime.utcnow() - cutoff
+ cutoff_time = utc_now() - cutoff
errors = MirrorLog.objects.filter(
is_success=False, check_time__gte=cutoff_time,
url__mirror__active=True, url__mirror__public=True).values(