summaryrefslogtreecommitdiff
path: root/devel
diff options
context:
space:
mode:
Diffstat (limited to 'devel')
-rw-r--r--devel/management/commands/reporead.py36
-rw-r--r--devel/urls.py2
-rw-r--r--devel/views.py33
3 files changed, 27 insertions, 44 deletions
diff --git a/devel/management/commands/reporead.py b/devel/management/commands/reporead.py
index 7373c56d..40329f95 100644
--- a/devel/management/commands/reporead.py
+++ b/devel/management/commands/reporead.py
@@ -22,6 +22,7 @@ import tarfile
import logging
from datetime import datetime
from optparse import make_option
+from pytz import utc
from django.core.management.base import BaseCommand, CommandError
from django.db import connections, router, transaction
@@ -29,8 +30,10 @@ from django.db.utils import IntegrityError
from devel.utils import UserFinder
from main.models import Arch, Package, PackageDepend, PackageFile, Repo
+from main.utils import utc_now
from packages.models import Conflict, Provision, Replacement
+
logging.basicConfig(
level=logging.WARNING,
format='%(asctime)s -> %(levelname)s: %(message)s',
@@ -113,7 +116,8 @@ class RepoPackage(object):
self.epoch = int(match.group(2))
elif k == 'builddate':
try:
- self.builddate = datetime.utcfromtimestamp(int(v[0]))
+ builddate = datetime.utcfromtimestamp(int(v[0]))
+ self.builddate = builddate.replace(tzinfo=utc)
except ValueError:
try:
self.builddate = datetime.strptime(v[0],
@@ -270,33 +274,21 @@ def populate_files(dbpkg, repopkg, force=False):
delete_pkg_files(dbpkg)
logger.info("adding %d files for package %s",
len(repopkg.files), dbpkg.pkgname)
+ pkg_files = []
for f in repopkg.files:
dirname, filename = f.rsplit('/', 1)
if filename == '':
filename = None
- # this is basically like calling dbpkg.packagefile_set.create(),
- # but much faster as we can skip a lot of the repeated code paths
- # TODO use Django 1.4 bulk_create
pkgfile = PackageFile(pkg=dbpkg,
is_directory=(filename is None),
directory=dirname + '/',
filename=filename)
- pkgfile.save(force_insert=True)
- dbpkg.files_last_update = datetime.utcnow()
+ pkg_files.append(pkgfile)
+ PackageFile.objects.bulk_create(pkg_files)
+ dbpkg.files_last_update = utc_now()
dbpkg.save()
-def select_pkg_for_update(dbpkg):
- database = router.db_for_write(Package, instance=dbpkg)
- connection = connections[database]
- if 'sqlite' in connection.settings_dict['ENGINE'].lower():
- return dbpkg
- new_pkg = Package.objects.raw(
- 'SELECT * FROM packages WHERE id = %s FOR UPDATE',
- [dbpkg.id])
- return list(new_pkg)[0]
-
-
def update_common(archname, reponame, pkgs, sanity_check=True):
# If isolation level is repeatable-read, we need to ensure each package
# update starts a new transaction and re-queries the database as
@@ -363,7 +355,7 @@ def db_update(archname, reponame, pkgs, force=False):
dbpkg = Package(pkgname=pkg.name, arch=architecture, repo=repository)
try:
with transaction.commit_on_success():
- populate_pkg(dbpkg, pkg, timestamp=datetime.utcnow())
+ populate_pkg(dbpkg, pkg, timestamp=utc_now())
except IntegrityError:
logger.warning("Could not add package %s; "
"not fatal if another thread beat us to it.",
@@ -390,14 +382,13 @@ def db_update(archname, reponame, pkgs, force=False):
if not force and pkg_same_version(pkg, dbpkg):
continue
elif not force:
- timestamp = datetime.utcnow()
+ timestamp = utc_now()
# The odd select_for_update song and dance here are to ensure
# simultaneous updates don't happen on a package, causing
# files/depends/all related items to be double-imported.
with transaction.commit_on_success():
- # TODO Django 1.4 select_for_update() will work once released
- dbpkg = select_pkg_for_update(dbpkg)
+ dbpkg = Package.objects.select_for_update().get(id=dbpkg.id)
if not force and pkg_same_version(pkg, dbpkg):
logger.debug("Package %s was already updated", pkg.name)
continue
@@ -428,8 +419,7 @@ def filesonly_update(archname, reponame, pkgs, force=False):
elif not force and dbpkg.files_last_update > dbpkg.last_update:
logger.debug("Files for %s are up to date", pkg.name)
continue
- # TODO Django 1.4 select_for_update() will work once released
- dbpkg = select_pkg_for_update(dbpkg)
+ dbpkg = Package.objects.select_for_update().get(id=dbpkg.id)
logger.debug("Checking files for package %s", pkg.name)
populate_files(dbpkg, pkg, force=force)
diff --git a/devel/urls.py b/devel/urls.py
index 07cb321b..31afc86b 100644
--- a/devel/urls.py
+++ b/devel/urls.py
@@ -1,4 +1,4 @@
-from django.conf.urls.defaults import patterns
+from django.conf.urls import patterns
urlpatterns = patterns('devel.views',
(r'^admin_log/$','admin_log'),
diff --git a/devel/views.py b/devel/views.py
index 328d52e4..3a9be757 100644
--- a/devel/views.py
+++ b/devel/views.py
@@ -1,3 +1,10 @@
+from datetime import datetime, timedelta
+import operator
+import pytz
+import random
+from string import ascii_letters, digits
+import time
+
from django import forms
from django.http import HttpResponseRedirect
from django.contrib.auth.decorators import \
@@ -16,19 +23,13 @@ from django.views.generic.simple import direct_to_template
from django.utils.http import http_date
from main.models import Package, PackageDepend, PackageFile, TodolistPkg
-from main.models import Arch, Repo
-from main.models import UserProfile
+from main.models import Arch, Repo, UserProfile
+from main.utils import utc_now
from packages.models import PackageRelation
from packages.utils import get_signoff_groups
from todolists.utils import get_annotated_todolists
from .utils import get_annotated_maintainers
-from datetime import datetime, timedelta
-import operator
-import pytz
-import random
-from string import ascii_letters, digits
-import time
@login_required
def index(request):
@@ -85,22 +86,14 @@ def clock(request):
devs = User.objects.filter(is_active=True).order_by(
'first_name', 'last_name').select_related('userprofile')
- now = datetime.now()
- utc_now = datetime.utcnow().replace(tzinfo=pytz.utc)
- # now annotate each dev object with their current time
- for dev in devs:
- tz = pytz.timezone(dev.userprofile.time_zone)
- dev.current_time = utc_now.astimezone(tz)
-
+ now = utc_now()
page_dict = {
'developers': devs,
- 'now': now,
- 'utc_now': utc_now,
+ 'utc_now': now,
}
response = direct_to_template(request, 'devel/clock.html', page_dict)
if not response.has_header('Expires'):
- # why this works only with the non-UTC date I have no idea...
expire_time = now.replace(second=0, microsecond=0)
expire_time += timedelta(minutes=1)
expire_time = time.mktime(expire_time.timetuple())
@@ -168,12 +161,12 @@ def report(request, report_name, username=None):
if report_name == 'old':
title = 'Packages last built more than two years ago'
- cutoff = datetime.utcnow() - timedelta(days=365 * 2)
+ cutoff = utc_now() - timedelta(days=365 * 2)
packages = packages.filter(
build_date__lt=cutoff).order_by('build_date')
elif report_name == 'long-out-of-date':
title = 'Packages marked out-of-date more than 90 days ago'
- cutoff = datetime.utcnow() - timedelta(days=90)
+ cutoff = utc_now() - timedelta(days=90)
packages = packages.filter(
flag_date__lt=cutoff).order_by('flag_date')
elif report_name == 'big':