summaryrefslogtreecommitdiff
path: root/packages
diff options
context:
space:
mode:
Diffstat (limited to 'packages')
-rw-r--r--packages/admin.py3
-rw-r--r--packages/management/__init__.py0
-rw-r--r--packages/management/commands/__init__.py0
-rw-r--r--packages/management/commands/populate_signoffs.py88
-rw-r--r--packages/management/commands/signoff_report.py125
-rw-r--r--packages/migrations/0010_auto__add_signoffspecification.py183
-rw-r--r--packages/migrations/0011_auto__chg_field_signoffspecification_user.py165
-rw-r--r--packages/models.py104
-rw-r--r--packages/templatetags/package_extras.py48
-rw-r--r--packages/urls.py3
-rw-r--r--packages/utils.py229
-rw-r--r--packages/views.py608
-rw-r--r--packages/views/__init__.py268
-rw-r--r--packages/views/flag.py121
-rw-r--r--packages/views/search.py168
-rw-r--r--packages/views/signoff.py193
16 files changed, 1675 insertions, 631 deletions
diff --git a/packages/admin.py b/packages/admin.py
index 3ecfdbb1..01b6ed6c 100644
--- a/packages/admin.py
+++ b/packages/admin.py
@@ -3,8 +3,9 @@ from django.contrib import admin
from .models import PackageRelation
class PackageRelationAdmin(admin.ModelAdmin):
- list_display = ('user', 'pkgbase', 'type')
+ list_display = ('user', 'pkgbase', 'type', 'created')
list_filter = ('type', 'user')
+ search_fields = ('user__username', 'pkgbase')
admin.site.register(PackageRelation, PackageRelationAdmin)
diff --git a/packages/management/__init__.py b/packages/management/__init__.py
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/packages/management/__init__.py
diff --git a/packages/management/commands/__init__.py b/packages/management/commands/__init__.py
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/packages/management/commands/__init__.py
diff --git a/packages/management/commands/populate_signoffs.py b/packages/management/commands/populate_signoffs.py
new file mode 100644
index 00000000..ce5ec734
--- /dev/null
+++ b/packages/management/commands/populate_signoffs.py
@@ -0,0 +1,88 @@
+# -*- coding: utf-8 -*-
+"""
+populate_signoffs command
+
+Pull the latest commit message from SVN for a given package that is
+signoff-eligible and does not have an existing comment attached.
+
+Usage: ./manage.py populate_signoffs
+"""
+
+from datetime import datetime
+import logging
+import subprocess
+import sys
+from xml.etree.ElementTree import XML
+
+from django.conf import settings
+from django.contrib.auth.models import User
+from django.core.management.base import NoArgsCommand
+
+from ...models import SignoffSpecification
+from ...utils import get_signoff_groups
+from devel.utils import UserFinder
+
+logging.basicConfig(
+ level=logging.INFO,
+ format='%(asctime)s -> %(levelname)s: %(message)s',
+ datefmt='%Y-%m-%d %H:%M:%S',
+ stream=sys.stderr)
+logger = logging.getLogger()
+
+class Command(NoArgsCommand):
+ help = "Pull the latest commit message from SVN for a given package that is signoff-eligible and does not have an existing comment attached"
+
+ def handle_noargs(self, **options):
+ v = int(options.get('verbosity', None))
+ if v == 0:
+ logger.level = logging.ERROR
+ elif v == 1:
+ logger.level = logging.INFO
+ elif v == 2:
+ logger.level = logging.DEBUG
+
+ return add_signoff_comments()
+
+def svn_log(pkgbase, repo):
+ path = '%s%s/%s/trunk/' % (settings.SVN_BASE_URL, repo.svn_root, pkgbase)
+ cmd = ['svn', 'log', '--limit=1', '--xml', path]
+ log_data = subprocess.check_output(cmd)
+ # the XML format is very very simple, especially with only one revision
+ xml = XML(log_data)
+ revision = int(xml.find('logentry').get('revision'))
+ date = datetime.strptime(xml.findtext('logentry/date'),
+ '%Y-%m-%dT%H:%M:%S.%fZ')
+ return {
+ 'revision': revision,
+ 'date': date,
+ 'author': xml.findtext('logentry/author'),
+ 'message': xml.findtext('logentry/msg'),
+ }
+
+def create_specification(package, log, finder):
+ trimmed_message = log['message'].strip()
+ spec = SignoffSpecification(pkgbase=package.pkgbase,
+ pkgver=package.pkgver, pkgrel=package.pkgrel,
+ epoch=package.epoch, arch=package.arch, repo=package.repo,
+ comments=trimmed_message)
+ spec.user = finder.find_by_username(log['author'])
+ return spec
+
+def add_signoff_comments():
+ logger.info("getting all signoff groups")
+ groups = get_signoff_groups()
+ logger.info("%d signoff groups found", len(groups))
+
+ finder = UserFinder()
+
+ for group in groups:
+ if not group.default_spec:
+ continue
+
+ logger.debug("getting SVN log for %s (%s)", group.pkgbase, group.repo)
+ log = svn_log(group.pkgbase, group.repo)
+ logger.info("creating spec with SVN message for %s", group.pkgbase)
+ spec = create_specification(group.packages[0], log, finder)
+ spec.save()
+
+# vim: set ts=4 sw=4 et:
diff --git a/packages/management/commands/signoff_report.py b/packages/management/commands/signoff_report.py
new file mode 100644
index 00000000..3b67f518
--- /dev/null
+++ b/packages/management/commands/signoff_report.py
@@ -0,0 +1,125 @@
+# -*- coding: utf-8 -*-
+"""
+signoff_report command
+
+Send an email summarizing the state of outstanding signoffs for the given
+repository.
+
+Usage: ./manage.py signoff_report <email> <repository>
+"""
+
+from django.core.mail import send_mail
+from django.core.urlresolvers import reverse
+from django.core.management.base import BaseCommand, CommandError
+from django.contrib.auth.models import User
+from django.contrib.sites.models import Site
+from django.db.models import Count
+from django.template import loader, Context
+
+from collections import namedtuple
+from datetime import datetime, timedelta
+import logging
+from operator import attrgetter
+import sys
+
+from main.models import Repo
+from packages.models import Signoff
+from packages.utils import get_signoff_groups
+
+logging.basicConfig(
+ level=logging.INFO,
+ format='%(asctime)s -> %(levelname)s: %(message)s',
+ datefmt='%Y-%m-%d %H:%M:%S',
+ stream=sys.stderr)
+logger = logging.getLogger()
+
+class Command(BaseCommand):
+ args = "<email> <repository>"
+ help = "Send a signoff report for the given repository."
+
+ def handle(self, *args, **options):
+ v = int(options.get('verbosity', None))
+ if v == 0:
+ logger.level = logging.ERROR
+ elif v == 1:
+ logger.level = logging.INFO
+ elif v == 2:
+ logger.level = logging.DEBUG
+
+ if len(args) != 2:
+ raise CommandError("email and repository must be provided")
+
+ return generate_report(args[0], args[1])
+
+def generate_report(email, repo_name):
+ repo = Repo.objects.get(name__iexact=repo_name)
+ # Collect all existing signoffs for these packages
+ signoff_groups = sorted(get_signoff_groups([repo]),
+ key=attrgetter('target_repo', 'arch', 'pkgbase'))
+ disabled = []
+ bad = []
+ complete = []
+ incomplete = []
+ new = []
+ old = []
+
+ new_hours = 24
+ old_days = 14
+ now = datetime.utcnow()
+ new_cutoff = now - timedelta(hours=new_hours)
+ old_cutoff = now - timedelta(days=old_days)
+
+ if len(signoff_groups) == 0:
+ # no need to send an email at all
+ return
+
+ for group in signoff_groups:
+ spec = group.specification
+ if spec.known_bad:
+ bad.append(group)
+ elif not spec.enabled:
+ disabled.append(group)
+ elif group.approved():
+ complete.append(group)
+ else:
+ incomplete.append(group)
+
+ if group.package.last_update > new_cutoff:
+ new.append(group)
+ if group.package.last_update < old_cutoff:
+ old.append(group)
+
+ old.sort(key=attrgetter('last_update'))
+
+ proto = 'https'
+ domain = Site.objects.get_current().domain
+ signoffs_url = '%s://%s%s' % (proto, domain, reverse('package-signoffs'))
+
+ # and the fun bit
+ Leader = namedtuple('Leader', ['user', 'count'])
+ leaders = Signoff.objects.filter(created__gt=new_cutoff,
+ revoked__isnull=True).values_list('user').annotate(
+ signoff_count=Count('pk')).order_by('-signoff_count')[:5]
+ users = User.objects.in_bulk([l[0] for l in leaders])
+ leaders = (Leader(users[l[0]], l[1]) for l in leaders)
+
+ subject = 'Signoff report for [%s]' % repo.name.lower()
+ t = loader.get_template('packages/signoff_report.txt')
+ c = Context({
+ 'repo': repo,
+ 'signoffs_url': signoffs_url,
+ 'disabled': disabled,
+ 'bad': bad,
+ 'all': signoff_groups,
+ 'incomplete': incomplete,
+ 'complete': complete,
+ 'new': new,
+ 'new_hours': new_hours,
+ 'old': old,
+ 'old_days': old_days,
+ 'leaders': leaders,
+ })
+ from_addr = 'Arch Website Notification <nobody@archlinux.org>'
+ send_mail(subject, t.render(c), from_addr, [email])
+
+# vim: set ts=4 sw=4 et:
diff --git a/packages/migrations/0010_auto__add_signoffspecification.py b/packages/migrations/0010_auto__add_signoffspecification.py
new file mode 100644
index 00000000..da24824e
--- /dev/null
+++ b/packages/migrations/0010_auto__add_signoffspecification.py
@@ -0,0 +1,183 @@
+# encoding: utf-8
+import datetime
+from south.db import db
+from south.v2 import SchemaMigration
+from django.db import models
+
+class Migration(SchemaMigration):
+
+ def forwards(self, orm):
+ db.create_table('packages_signoffspecification', (
+ ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
+ ('pkgbase', self.gf('django.db.models.fields.CharField')(max_length=255, db_index=True)),
+ ('pkgver', self.gf('django.db.models.fields.CharField')(max_length=255)),
+ ('pkgrel', self.gf('django.db.models.fields.CharField')(max_length=255)),
+ ('epoch', self.gf('django.db.models.fields.PositiveIntegerField')(default=0)),
+ ('arch', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['main.Arch'])),
+ ('repo', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['main.Repo'])),
+ ('user', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['auth.User'])),
+ ('created', self.gf('django.db.models.fields.DateTimeField')()),
+ ('required', self.gf('django.db.models.fields.PositiveIntegerField')(default=2)),
+ ('enabled', self.gf('django.db.models.fields.BooleanField')(default=True)),
+ ('known_bad', self.gf('django.db.models.fields.BooleanField')(default=False)),
+ ('comments', self.gf('django.db.models.fields.TextField')(null=True, blank=True)),
+ ))
+ db.send_create_signal('packages', ['SignoffSpecification'])
+
+
+ def backwards(self, orm):
+ db.delete_table('packages_signoffspecification')
+
+
+ models = {
+ 'auth.group': {
+ 'Meta': {'object_name': 'Group'},
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}),
+ 'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})
+ },
+ 'auth.permission': {
+ 'Meta': {'ordering': "('content_type__app_label', 'content_type__model', 'codename')", 'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'},
+ 'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
+ },
+ 'auth.user': {
+ 'Meta': {'object_name': 'User'},
+ 'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+ 'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
+ 'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
+ 'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+ 'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+ 'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
+ 'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
+ 'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}),
+ 'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})
+ },
+ 'contenttypes.contenttype': {
+ 'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
+ 'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
+ },
+ 'main.arch': {
+ 'Meta': {'ordering': "['name']", 'object_name': 'Arch', 'db_table': "'arches'"},
+ 'agnostic': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '255'})
+ },
+ 'main.package': {
+ 'Meta': {'ordering': "('pkgname',)", 'object_name': 'Package', 'db_table': "'packages'"},
+ 'arch': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'packages'", 'to': "orm['main.Arch']"}),
+ 'build_date': ('django.db.models.fields.DateTimeField', [], {'null': 'True'}),
+ 'compressed_size': ('main.models.PositiveBigIntegerField', [], {}),
+ 'epoch': ('django.db.models.fields.PositiveIntegerField', [], {'default': '0'}),
+ 'filename': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+ 'files_last_update': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}),
+ 'flag_date': ('django.db.models.fields.DateTimeField', [], {'null': 'True'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'installed_size': ('main.models.PositiveBigIntegerField', [], {}),
+ 'last_update': ('django.db.models.fields.DateTimeField', [], {}),
+ 'packager': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']", 'null': 'True'}),
+ 'packager_str': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+ 'pgp_signature': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
+ 'pkgbase': ('django.db.models.fields.CharField', [], {'max_length': '255', 'db_index': 'True'}),
+ 'pkgdesc': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True'}),
+ 'pkgname': ('django.db.models.fields.CharField', [], {'max_length': '255', 'db_index': 'True'}),
+ 'pkgrel': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+ 'pkgver': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+ 'repo': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'packages'", 'to': "orm['main.Repo']"}),
+ 'url': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True'})
+ },
+ 'main.repo': {
+ 'Meta': {'ordering': "['name']", 'object_name': 'Repo', 'db_table': "'repos'"},
+ 'bugs_category': ('django.db.models.fields.SmallIntegerField', [], {'default': '0'}),
+ 'bugs_project': ('django.db.models.fields.SmallIntegerField', [], {'default': '1'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '255'}),
+ 'staging': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'svn_root': ('django.db.models.fields.CharField', [], {'max_length': '64'}),
+ 'testing': ('django.db.models.fields.BooleanField', [], {'default': 'False'})
+ },
+ 'packages.conflict': {
+ 'Meta': {'ordering': "['name']", 'object_name': 'Conflict'},
+ 'comparison': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '255'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '255', 'db_index': 'True'}),
+ 'pkg': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'conflicts'", 'to': "orm['main.Package']"}),
+ 'version': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '255'})
+ },
+ 'packages.license': {
+ 'Meta': {'ordering': "['name']", 'object_name': 'License'},
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+ 'pkg': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'licenses'", 'to': "orm['main.Package']"})
+ },
+ 'packages.packagegroup': {
+ 'Meta': {'object_name': 'PackageGroup'},
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '255', 'db_index': 'True'}),
+ 'pkg': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'groups'", 'to': "orm['main.Package']"})
+ },
+ 'packages.packagerelation': {
+ 'Meta': {'unique_together': "(('pkgbase', 'user', 'type'),)", 'object_name': 'PackageRelation'},
+ 'created': ('django.db.models.fields.DateTimeField', [], {}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'pkgbase': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+ 'type': ('django.db.models.fields.PositiveIntegerField', [], {'default': '1'}),
+ 'user': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'package_relations'", 'to': "orm['auth.User']"})
+ },
+ 'packages.provision': {
+ 'Meta': {'ordering': "['name']", 'object_name': 'Provision'},
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '255', 'db_index': 'True'}),
+ 'pkg': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'provides'", 'to': "orm['main.Package']"}),
+ 'version': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '255'})
+ },
+ 'packages.replacement': {
+ 'Meta': {'ordering': "['name']", 'object_name': 'Replacement'},
+ 'comparison': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '255'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '255', 'db_index': 'True'}),
+ 'pkg': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'replaces'", 'to': "orm['main.Package']"}),
+ 'version': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '255'})
+ },
+ 'packages.signoff': {
+ 'Meta': {'object_name': 'Signoff'},
+ 'arch': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['main.Arch']"}),
+ 'comments': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
+ 'created': ('django.db.models.fields.DateTimeField', [], {}),
+ 'epoch': ('django.db.models.fields.PositiveIntegerField', [], {'default': '0'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'pkgbase': ('django.db.models.fields.CharField', [], {'max_length': '255', 'db_index': 'True'}),
+ 'pkgrel': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+ 'pkgver': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+ 'repo': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['main.Repo']"}),
+ 'revoked': ('django.db.models.fields.DateTimeField', [], {'null': 'True'}),
+ 'user': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'package_signoffs'", 'to': "orm['auth.User']"})
+ },
+ 'packages.signoffspecification': {
+ 'Meta': {'object_name': 'SignoffSpecification'},
+ 'arch': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['main.Arch']"}),
+ 'comments': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
+ 'created': ('django.db.models.fields.DateTimeField', [], {}),
+ 'enabled': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+ 'epoch': ('django.db.models.fields.PositiveIntegerField', [], {'default': '0'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'known_bad': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'pkgbase': ('django.db.models.fields.CharField', [], {'max_length': '255', 'db_index': 'True'}),
+ 'pkgrel': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+ 'pkgver': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+ 'repo': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['main.Repo']"}),
+ 'required': ('django.db.models.fields.PositiveIntegerField', [], {'default': '2'}),
+ 'user': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']"})
+ }
+ }
+
+ complete_apps = ['packages']
diff --git a/packages/migrations/0011_auto__chg_field_signoffspecification_user.py b/packages/migrations/0011_auto__chg_field_signoffspecification_user.py
new file mode 100644
index 00000000..f6e3cdd9
--- /dev/null
+++ b/packages/migrations/0011_auto__chg_field_signoffspecification_user.py
@@ -0,0 +1,165 @@
+# encoding: utf-8
+from south.db import db
+from south.v2 import SchemaMigration
+from django.db import models
+
+class Migration(SchemaMigration):
+
+ def forwards(self, orm):
+ db.alter_column('packages_signoffspecification', 'user_id', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['auth.User'], null=True))
+
+ def backwards(self, orm):
+ db.alter_column('packages_signoffspecification', 'user_id', self.gf('django.db.models.fields.related.ForeignKey')(default=1, to=orm['auth.User']))
+
+ models = {
+ 'auth.group': {
+ 'Meta': {'object_name': 'Group'},
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}),
+ 'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})
+ },
+ 'auth.permission': {
+ 'Meta': {'ordering': "('content_type__app_label', 'content_type__model', 'codename')", 'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'},
+ 'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
+ },
+ 'auth.user': {
+ 'Meta': {'object_name': 'User'},
+ 'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+ 'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
+ 'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
+ 'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+ 'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+ 'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
+ 'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
+ 'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}),
+ 'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})
+ },
+ 'contenttypes.contenttype': {
+ 'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
+ 'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
+ },
+ 'main.arch': {
+ 'Meta': {'ordering': "['name']", 'object_name': 'Arch', 'db_table': "'arches'"},
+ 'agnostic': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '255'})
+ },
+ 'main.package': {
+ 'Meta': {'ordering': "('pkgname',)", 'object_name': 'Package', 'db_table': "'packages'"},
+ 'arch': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'packages'", 'to': "orm['main.Arch']"}),
+ 'build_date': ('django.db.models.fields.DateTimeField', [], {'null': 'True'}),
+ 'compressed_size': ('main.models.PositiveBigIntegerField', [], {}),
+ 'epoch': ('django.db.models.fields.PositiveIntegerField', [], {'default': '0'}),
+ 'filename': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+ 'files_last_update': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}),
+ 'flag_date': ('django.db.models.fields.DateTimeField', [], {'null': 'True'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'installed_size': ('main.models.PositiveBigIntegerField', [], {}),
+ 'last_update': ('django.db.models.fields.DateTimeField', [], {}),
+ 'packager': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']", 'null': 'True'}),
+ 'packager_str': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+ 'pgp_signature': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
+ 'pkgbase': ('django.db.models.fields.CharField', [], {'max_length': '255', 'db_index': 'True'}),
+ 'pkgdesc': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True'}),
+ 'pkgname': ('django.db.models.fields.CharField', [], {'max_length': '255', 'db_index': 'True'}),
+ 'pkgrel': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+ 'pkgver': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+ 'repo': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'packages'", 'to': "orm['main.Repo']"}),
+ 'url': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True'})
+ },
+ 'main.repo': {
+ 'Meta': {'ordering': "['name']", 'object_name': 'Repo', 'db_table': "'repos'"},
+ 'bugs_category': ('django.db.models.fields.SmallIntegerField', [], {'default': '0'}),
+ 'bugs_project': ('django.db.models.fields.SmallIntegerField', [], {'default': '1'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '255'}),
+ 'staging': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'svn_root': ('django.db.models.fields.CharField', [], {'max_length': '64'}),
+ 'testing': ('django.db.models.fields.BooleanField', [], {'default': 'False'})
+ },
+ 'packages.conflict': {
+ 'Meta': {'ordering': "['name']", 'object_name': 'Conflict'},
+ 'comparison': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '255'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '255', 'db_index': 'True'}),
+ 'pkg': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'conflicts'", 'to': "orm['main.Package']"}),
+ 'version': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '255'})
+ },
+ 'packages.license': {
+ 'Meta': {'ordering': "['name']", 'object_name': 'License'},
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+ 'pkg': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'licenses'", 'to': "orm['main.Package']"})
+ },
+ 'packages.packagegroup': {
+ 'Meta': {'object_name': 'PackageGroup'},
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '255', 'db_index': 'True'}),
+ 'pkg': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'groups'", 'to': "orm['main.Package']"})
+ },
+ 'packages.packagerelation': {
+ 'Meta': {'unique_together': "(('pkgbase', 'user', 'type'),)", 'object_name': 'PackageRelation'},
+ 'created': ('django.db.models.fields.DateTimeField', [], {}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'pkgbase': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+ 'type': ('django.db.models.fields.PositiveIntegerField', [], {'default': '1'}),
+ 'user': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'package_relations'", 'to': "orm['auth.User']"})
+ },
+ 'packages.provision': {
+ 'Meta': {'ordering': "['name']", 'object_name': 'Provision'},
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '255', 'db_index': 'True'}),
+ 'pkg': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'provides'", 'to': "orm['main.Package']"}),
+ 'version': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '255'})
+ },
+ 'packages.replacement': {
+ 'Meta': {'ordering': "['name']", 'object_name': 'Replacement'},
+ 'comparison': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '255'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '255', 'db_index': 'True'}),
+ 'pkg': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'replaces'", 'to': "orm['main.Package']"}),
+ 'version': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '255'})
+ },
+ 'packages.signoff': {
+ 'Meta': {'object_name': 'Signoff'},
+ 'arch': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['main.Arch']"}),
+ 'comments': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
+ 'created': ('django.db.models.fields.DateTimeField', [], {}),
+ 'epoch': ('django.db.models.fields.PositiveIntegerField', [], {'default': '0'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'pkgbase': ('django.db.models.fields.CharField', [], {'max_length': '255', 'db_index': 'True'}),
+ 'pkgrel': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+ 'pkgver': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+ 'repo': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['main.Repo']"}),
+ 'revoked': ('django.db.models.fields.DateTimeField', [], {'null': 'True'}),
+ 'user': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'package_signoffs'", 'to': "orm['auth.User']"})
+ },
+ 'packages.signoffspecification': {
+ 'Meta': {'object_name': 'SignoffSpecification'},
+ 'arch': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['main.Arch']"}),
+ 'comments': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
+ 'created': ('django.db.models.fields.DateTimeField', [], {}),
+ 'enabled': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+ 'epoch': ('django.db.models.fields.PositiveIntegerField', [], {'default': '0'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'known_bad': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'pkgbase': ('django.db.models.fields.CharField', [], {'max_length': '255', 'db_index': 'True'}),
+ 'pkgrel': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+ 'pkgver': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+ 'repo': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['main.Repo']"}),
+ 'required': ('django.db.models.fields.PositiveIntegerField', [], {'default': '2'}),
+ 'user': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']", 'null': 'True'})
+ }
+ }
+
+ complete_apps = ['packages']
diff --git a/packages/models.py b/packages/models.py
index d2fe1878..0d02ab31 100644
--- a/packages/models.py
+++ b/packages/models.py
@@ -1,3 +1,5 @@
+from collections import namedtuple
+
from django.db import models
from django.db.models.signals import pre_save, post_save
from django.contrib.auth.models import User
@@ -38,6 +40,90 @@ class PackageRelation(models.Model):
class Meta:
unique_together = (('pkgbase', 'user', 'type'),)
+
+class SignoffSpecificationManager(models.Manager):
+ def get_from_package(self, pkg):
+ '''Utility method to pull all relevant name-version fields from a
+ package and get a matching signoff specification.'''
+ return self.get(
+ pkgbase=pkg.pkgbase, pkgver=pkg.pkgver, pkgrel=pkg.pkgrel,
+ epoch=pkg.epoch, arch=pkg.arch, repo=pkg.repo)
+
+ def get_or_default_from_package(self, pkg):
+ '''utility method to pull all relevant name-version fields from a
+ package and get a matching signoff specification, or return the default
+ base case.'''
+ try:
+ return self.get(
+ pkgbase=pkg.pkgbase, pkgver=pkg.pkgver, pkgrel=pkg.pkgrel,
+ epoch=pkg.epoch, arch=pkg.arch, repo=pkg.repo)
+ except SignoffSpecification.DoesNotExist:
+ return DEFAULT_SIGNOFF_SPEC
+
+class SignoffSpecification(models.Model):
+ '''
+ A specification for the signoff policy for this particular revision of a
+ package. The default is requiring two signoffs for a given package. These
+ are created only if necessary; e.g., if one wanted to override the
+ required=2 attribute, otherwise a sane default object is used.
+ '''
+ pkgbase = models.CharField(max_length=255, db_index=True)
+ pkgver = models.CharField(max_length=255)
+ pkgrel = models.CharField(max_length=255)
+ epoch = models.PositiveIntegerField(default=0)
+ arch = models.ForeignKey('main.Arch')
+ repo = models.ForeignKey('main.Repo')
+ user = models.ForeignKey(User, null=True)
+ created = models.DateTimeField(editable=False)
+ required = models.PositiveIntegerField(default=2,
+ help_text="How many signoffs are required for this package?")
+ enabled = models.BooleanField(default=True,
+ help_text="Is this package eligible for signoffs?")
+ known_bad = models.BooleanField(default=False,
+ help_text="Is package is known to be broken in some way?")
+ comments = models.TextField(null=True, blank=True)
+
+ objects = SignoffSpecificationManager()
+
+ @property
+ def full_version(self):
+ if self.epoch > 0:
+ return u'%d:%s-%s' % (self.epoch, self.pkgver, self.pkgrel)
+ return u'%s-%s' % (self.pkgver, self.pkgrel)
+
+ def __unicode__(self):
+ return u'%s-%s' % (self.pkgbase, self.full_version)
+
+
+# fake default signoff spec when we don't have a persisted one in the database
+FakeSignoffSpecification = namedtuple('FakeSignoffSpecification',
+ ('required', 'enabled', 'known_bad', 'comments'))
+DEFAULT_SIGNOFF_SPEC = FakeSignoffSpecification(2, True, False, u'')
+
+
+class SignoffManager(models.Manager):
+ def get_from_package(self, pkg, user, revoked=False):
+ '''Utility method to pull all relevant name-version fields from a
+ package and get a matching signoff.'''
+ not_revoked = not revoked
+ return self.get(
+ pkgbase=pkg.pkgbase, pkgver=pkg.pkgver, pkgrel=pkg.pkgrel,
+ epoch=pkg.epoch, arch=pkg.arch, repo=pkg.repo,
+ revoked__isnull=not_revoked, user=user)
+
+ def get_or_create_from_package(self, pkg, user):
+ '''Utility method to pull all relevant name-version fields from a
+ package and get or create a matching signoff.'''
+ return self.get_or_create(
+ pkgbase=pkg.pkgbase, pkgver=pkg.pkgver, pkgrel=pkg.pkgrel,
+ epoch=pkg.epoch, arch=pkg.arch, repo=pkg.repo,
+ revoked=None, user=user)
+
+ def for_package(self, pkg):
+ return self.select_related('user').filter(
+ pkgbase=pkg.pkgbase, pkgver=pkg.pkgver, pkgrel=pkg.pkgrel,
+ epoch=pkg.epoch, arch=pkg.arch, repo=pkg.repo)
+
class Signoff(models.Model):
'''
A signoff for a package (by pkgbase) at a given point in time. These are
@@ -55,14 +141,14 @@ class Signoff(models.Model):
revoked = models.DateTimeField(null=True)
comments = models.TextField(null=True, blank=True)
- REQUIRED = 2
+ objects = SignoffManager()
@property
def packages(self):
# TODO: delayed import to avoid circular reference
from main.models import Package
return Package.objects.normal().filter(pkgbase=self.pkgbase,
- pkgver=self.pkgver, pkgrel=self.pkgrel, epoch=pkg.epoch,
+ pkgver=self.pkgver, pkgrel=self.pkgrel, epoch=self.epoch,
arch=self.arch, repo=self.repo)
@property
@@ -72,8 +158,11 @@ class Signoff(models.Model):
return u'%s-%s' % (self.pkgver, self.pkgrel)
def __unicode__(self):
- return u'%s-%s: %s' % (
- self.pkgbase, self.full_version, self.user)
+ revoked = u''
+ if self.revoked:
+ revoked = u' (revoked)'
+ return u'%s-%s: %s%s' % (
+ self.pkgbase, self.full_version, self.user, revoked)
class PackageGroup(models.Model):
'''
@@ -150,9 +239,8 @@ def remove_inactive_maintainers(sender, instance, created, **kwargs):
post_save.connect(remove_inactive_maintainers, sender=User,
dispatch_uid="packages.models")
-pre_save.connect(set_created_field, sender=PackageRelation,
- dispatch_uid="packages.models")
-pre_save.connect(set_created_field, sender=Signoff,
- dispatch_uid="packages.models")
+for sender in (PackageRelation, SignoffSpecification, Signoff):
+ pre_save.connect(set_created_field, sender=sender,
+ dispatch_uid="packages.models")
# vim: set ts=4 sw=4 et:
diff --git a/packages/templatetags/package_extras.py b/packages/templatetags/package_extras.py
index d4d0ca1a..fc2201e5 100644
--- a/packages/templatetags/package_extras.py
+++ b/packages/templatetags/package_extras.py
@@ -1,4 +1,4 @@
-from urllib import urlencode, quote as urlquote
+from urllib import urlencode, quote as urlquote, unquote
try:
from urlparse import parse_qs
except ImportError:
@@ -9,6 +9,21 @@ from django.utils.html import escape
register = template.Library()
+def link_encode(url, query, doseq=False):
+ data = urlencode(query, doseq).replace('&', '&amp;')
+ return "%s?%s" % (url, data)
+
+@register.filter
+def url_unquote(original_url):
+ try:
+ url = original_url
+ if isinstance(url, unicode):
+ url = url.encode('ascii')
+ url = unquote(url).decode('utf-8')
+ return url
+ except UnicodeError:
+ return original_url
+
class BuildQueryStringNode(template.Node):
def __init__(self, sortfield):
self.sortfield = sortfield
@@ -37,6 +52,15 @@ def do_buildsortqs(parser, token):
return BuildQueryStringNode(sortfield[1:-1])
@register.simple_tag
+def pkg_details_link(pkg):
+ template = '<a href="%s" title="View package details for %s">%s</a>'
+ return template % (pkg.get_absolute_url(), pkg.pkgname, pkg.pkgname)
+
+@register.simple_tag
+def multi_pkg_details(pkgs):
+ return ', '.join([pkg_details_link(pkg) for pkg in pkgs])
+
+@register.simple_tag
def userpkgs(user):
if user:
# TODO don't hardcode
@@ -48,22 +72,40 @@ def userpkgs(user):
)
return ''
+
+def svn_link(package, svnpath):
+ '''Helper function for the two real SVN link methods.'''
+ parts = (package.repo.svn_root, package.pkgbase, svnpath)
+ linkbase = "http://projects.archlinux.org/svntogit/%s.git/tree/%s/%s/"
+ return linkbase % tuple(urlquote(part) for part in parts)
+
+@register.simple_tag
+def svn_arch(package):
+ repo = package.repo.name.lower()
+ return svn_link(package, "repos/%s-%s" % (repo, package.arch.name))
+
+@register.simple_tag
+def svn_trunk(package):
+ return svn_link(package, "trunk")
+
@register.simple_tag
def bugs_list(package):
+ url = "https://bugs.parabolagnulinux.org/bugs/issue?"
data = {
'@action': 'search',
'title': package.pkgname,
}
- return "https://bugs.parabolagnulinux.org/bugs/issue?%s" % urlencode(data)
+ return link_encode(url, data)
@register.simple_tag
def bug_report(package):
+ url = "https://bugs.parabolagnulinux.org/bugs/issue?"
data = {
'@template': 'item',
'keyword': 'packages',
'title': '[%s]' % package.pkgname,
}
- return "https://bugs.parabolagnulinux.org/bugs/issue?%s" % urlencode(data)
+ return link_encode(url, data)
@register.simple_tag
def flag_unfree(package):
diff --git a/packages/urls.py b/packages/urls.py
index d7d01170..1f25e3fd 100644
--- a/packages/urls.py
+++ b/packages/urls.py
@@ -10,12 +10,15 @@ package_patterns = patterns('packages.views',
(r'^unflag/$', 'unflag'),
(r'^unflag/all/$', 'unflag_all'),
(r'^signoff/$', 'signoff_package'),
+ (r'^signoff/revoke/$', 'signoff_package', {'revoke': True}),
+ (r'^signoff/options/$', 'signoff_options'),
(r'^download/$', 'download'),
)
urlpatterns = patterns('packages.views',
(r'^flaghelp/$', 'flaghelp'),
(r'^signoffs/$', 'signoffs', {}, 'package-signoffs'),
+ (r'^signoffs/json/$', 'signoffs_json', {}, 'package-signoffs-json'),
(r'^update/$', 'update'),
(r'^$', 'search', {}, 'packages-search'),
diff --git a/packages/utils.py b/packages/utils.py
index c8c1f8a6..f8e1f2a1 100644
--- a/packages/utils.py
+++ b/packages/utils.py
@@ -2,11 +2,13 @@ from collections import defaultdict
from operator import itemgetter
from django.db import connection
-from django.db.models import Count, Max
+from django.db.models import Count, Max, F
+from django.contrib.auth.models import User
-from main.models import Package
-from main.utils import cache_function
-from .models import PackageGroup, PackageRelation, Signoff
+from main.models import Package, Arch, Repo
+from main.utils import cache_function, groupby_preserve_order, PackageStandin
+from .models import (PackageGroup, PackageRelation,
+ SignoffSpecification, Signoff, DEFAULT_SIGNOFF_SPEC)
@cache_function(300)
def get_group_info(include_arches=None):
@@ -47,6 +49,20 @@ def get_group_info(include_arches=None):
groups.extend(val.itervalues())
return sorted(groups, key=itemgetter('name', 'arch'))
+def get_split_packages_info():
+ '''Return info on split packages that do not have an actual package name
+ matching the split pkgbase.'''
+ pkgnames = Package.objects.values('pkgname')
+ split_pkgs = Package.objects.exclude(pkgname=F('pkgbase')).exclude(
+ pkgbase__in=pkgnames).values('pkgbase', 'repo', 'arch').annotate(
+ last_update=Max('last_update'))
+ all_arches = Arch.objects.in_bulk(set(s['arch'] for s in split_pkgs))
+ all_repos = Repo.objects.in_bulk(set(s['repo'] for s in split_pkgs))
+ for split in split_pkgs:
+ split['arch'] = all_arches[split['arch']]
+ split['repo'] = all_repos[split['repo']]
+ return split_pkgs
+
class Difference(object):
def __init__(self, pkgname, repo, pkg_a, pkg_b):
self.pkgname = pkgname
@@ -126,6 +142,7 @@ SELECT p.id, q.id
differences.sort(key=lambda a: (a.repo.name, a.pkgname))
return differences
+
def get_wrong_permissions():
sql = """
SELECT DISTINCT id
@@ -148,11 +165,128 @@ SELECT DISTINCT id
id__in=to_fetch)
return relations
-def get_current_signoffs():
- '''Returns a mapping of pkgbase -> signoff objects.'''
- sql = """
+
+def attach_maintainers(packages):
+ '''Given a queryset or something resembling it of package objects, find all
+ the maintainers and attach them to the packages to prevent N+1 query
+ cascading.'''
+ packages = list(packages)
+ pkgbases = set(p.pkgbase for p in packages)
+ rels = PackageRelation.objects.filter(type=PackageRelation.MAINTAINER,
+ pkgbase__in=pkgbases).values_list('pkgbase', 'user_id').distinct()
+
+ # get all the user objects we will need
+ user_ids = set(rel[1] for rel in rels)
+ users = User.objects.in_bulk(user_ids)
+
+ # now build a pkgbase -> [maintainers...] map
+ maintainers = defaultdict(list)
+ for rel in rels:
+ maintainers[rel[0]].append(users[rel[1]])
+
+ annotated = []
+ # and finally, attach the maintainer lists on the original packages
+ for package in packages:
+ package.maintainers = maintainers[package.pkgbase]
+ annotated.append(package)
+
+ return annotated
+
+
+def approved_by_signoffs(signoffs, spec):
+ if signoffs:
+ good_signoffs = sum(1 for s in signoffs if not s.revoked)
+ return good_signoffs >= spec.required
+ return False
+
+class PackageSignoffGroup(object):
+ '''Encompasses all packages in testing with the same pkgbase.'''
+ def __init__(self, packages):
+ if len(packages) == 0:
+ raise Exception
+ self.packages = packages
+ self.user = None
+ self.target_repo = None
+ self.signoffs = set()
+ self.specification = DEFAULT_SIGNOFF_SPEC
+ self.default_spec = True
+
+ first = packages[0]
+ self.pkgbase = first.pkgbase
+ self.arch = first.arch
+ self.repo = first.repo
+ self.version = ''
+ self.last_update = first.last_update
+ self.packager = first.packager
+ self.maintainers = first.maintainers
+
+ version = first.full_version
+ if all(version == pkg.full_version for pkg in packages):
+ self.version = version
+
+ @property
+ def package(self):
+ '''Try and return a relevant single package object representing this
+ group. Start by seeing if there is only one package, then look for the
+ matching package by name, finally falling back to a standin package
+ object.'''
+ if len(self.packages) == 1:
+ return self.packages[0]
+
+ same_pkgs = [p for p in self.packages if p.pkgname == p.pkgbase]
+ if same_pkgs:
+ return same_pkgs[0]
+
+ return PackageStandin(self.packages[0])
+
+ def find_signoffs(self, all_signoffs):
+ '''Look through a list of Signoff objects for ones matching this
+ particular group and store them on the object.'''
+ for s in all_signoffs:
+ if s.pkgbase != self.pkgbase:
+ continue
+ if self.version and not s.full_version == self.version:
+ continue
+ if s.arch_id == self.arch.id and s.repo_id == self.repo.id:
+ self.signoffs.add(s)
+
+ def find_specification(self, specifications):
+ for spec in specifications:
+ if spec.pkgbase != self.pkgbase:
+ continue
+ if self.version and not spec.full_version == self.version:
+ continue
+ if spec.arch_id == self.arch.id and spec.repo_id == self.repo.id:
+ self.specification = spec
+ self.default_spec = False
+ return
+
+ def approved(self):
+ return approved_by_signoffs(self.signoffs, self.specification)
+
+ @property
+ def completed(self):
+ return sum(1 for s in self.signoffs if not s.revoked)
+
+ @property
+ def required(self):
+ return self.specification.required
+
+ def user_signed_off(self, user=None):
+ '''Did a given user signoff on this package? user can be passed as an
+ argument, or attached to the group object itself so this can be called
+ from a template.'''
+ if user is None:
+ user = self.user
+ return user in (s.user for s in self.signoffs if not s.revoked)
+
+ def __unicode__(self):
+ return u'%s-%s (%s): %d' % (
+ self.pkgbase, self.version, self.arch, len(self.signoffs))
+
+_SQL_SPEC_OR_SIGNOFF = """
SELECT DISTINCT s.id
- FROM packages_signoff s
+ FROM %s s
JOIN packages p ON (
s.pkgbase = p.pkgbase
AND s.pkgver = p.pkgver
@@ -161,15 +295,88 @@ SELECT DISTINCT s.id
AND s.arch_id = p.arch_id
AND s.repo_id = p.repo_id
)
- JOIN repos r ON p.repo_id = r.id
- WHERE r.testing = %s
+ AND p.repo_id IN (%s)
"""
+
+def get_current_signoffs(repos):
+ '''Returns a mapping of pkgbase -> signoff objects for the given repos.'''
cursor = connection.cursor()
- cursor.execute(sql, [True])
+ # query pre-process- fill in table name and placeholders for IN
+ sql = _SQL_SPEC_OR_SIGNOFF % ('packages_signoff',
+ ','.join(['%s' for r in repos]))
+ cursor.execute(sql, [r.pk for r in repos])
+
results = cursor.fetchall()
# fetch all of the returned signoffs by ID
to_fetch = [row[0] for row in results]
signoffs = Signoff.objects.select_related('user').in_bulk(to_fetch)
return signoffs.values()
+def get_current_specifications(repos):
+ '''Returns a mapping of pkgbase -> signoff specification objects for the
+ given repos.'''
+ cursor = connection.cursor()
+ sql = _SQL_SPEC_OR_SIGNOFF % ('packages_signoffspecification',
+ ','.join(['%s' for r in repos]))
+ cursor.execute(sql, [r.pk for r in repos])
+
+ results = cursor.fetchall()
+ to_fetch = [row[0] for row in results]
+ return SignoffSpecification.objects.in_bulk(to_fetch).values()
+
+def get_target_repo_map(repos):
+ sql = """
+SELECT DISTINCT p1.pkgbase, r.name
+ FROM packages p1
+ JOIN repos r ON p1.repo_id = r.id
+ JOIN packages p2 ON p1.pkgbase = p2.pkgbase
+ WHERE r.staging = %s
+ AND r.testing = %s
+ AND p2.repo_id IN (
+ """
+ sql += ','.join(['%s' for r in repos])
+ sql += ")"
+
+ params = [False, False]
+ params.extend(r.pk for r in repos)
+
+ cursor = connection.cursor()
+ cursor.execute(sql, params)
+ return dict(cursor.fetchall())
+
+def get_signoff_groups(repos=None, user=None):
+ if repos is None:
+ repos = Repo.objects.filter(testing=True)
+ repo_ids = [r.pk for r in repos]
+
+ test_pkgs = Package.objects.select_related(
+ 'arch', 'repo', 'packager').filter(repo__in=repo_ids)
+ packages = test_pkgs.order_by('pkgname')
+ packages = attach_maintainers(packages)
+
+ # Filter by user if asked to do so
+ if user is not None:
+ packages = [p for p in packages if user == p.packager
+ or user in p.maintainers]
+
+ # Collect all pkgbase values in testing repos
+ pkgtorepo = get_target_repo_map(repos)
+
+ # Collect all possible signoffs and specifications for these packages
+ signoffs = get_current_signoffs(repos)
+ specs = get_current_specifications(repos)
+
+ same_pkgbase_key = lambda x: (x.repo.name, x.arch.name, x.pkgbase)
+ grouped = groupby_preserve_order(packages, same_pkgbase_key)
+ signoff_groups = []
+ for group in grouped:
+ signoff_group = PackageSignoffGroup(group)
+ signoff_group.target_repo = pkgtorepo.get(signoff_group.pkgbase,
+ "Unknown")
+ signoff_group.find_signoffs(signoffs)
+ signoff_group.find_specification(specs)
+ signoff_groups.append(signoff_group)
+
+ return signoff_groups
+
# vim: set ts=4 sw=4 et:
diff --git a/packages/views.py b/packages/views.py
deleted file mode 100644
index f45c25d6..00000000
--- a/packages/views.py
+++ /dev/null
@@ -1,608 +0,0 @@
-from django import forms
-from django.contrib import messages
-from django.contrib.admin.widgets import AdminDateWidget
-from django.contrib.auth.models import User
-from django.contrib.auth.decorators import permission_required
-from django.conf import settings
-from django.core.mail import send_mail
-from django.core.serializers.json import DjangoJSONEncoder
-from django.db.models import Q
-from django.http import HttpResponse, Http404
-from django.shortcuts import get_object_or_404, get_list_or_404, redirect
-from django.template import loader, Context
-from django.utils import simplejson
-from django.views.decorators.cache import never_cache
-from django.views.decorators.http import require_POST
-from django.views.decorators.vary import vary_on_headers
-from django.views.generic import list_detail
-from django.views.generic.simple import direct_to_template
-
-from datetime import datetime
-from operator import attrgetter
-import string
-from urllib import urlencode
-
-from main.models import Package, PackageFile, Arch, Repo
-from main.utils import make_choice, groupby_preserve_order, PackageStandin
-from mirrors.models import MirrorUrl
-from .models import PackageRelation, PackageGroup, Signoff
-from .utils import (get_group_info, get_differences_info,
- get_wrong_permissions, get_current_signoffs)
-
-class PackageJSONEncoder(DjangoJSONEncoder):
- pkg_attributes = [ 'pkgname', 'pkgbase', 'repo', 'arch', 'pkgver',
- 'pkgrel', 'epoch', 'pkgdesc', 'url', 'filename', 'compressed_size',
- 'installed_size', 'build_date', 'last_update', 'flag_date' ]
-
- def default(self, obj):
- if hasattr(obj, '__iter__'):
- # mainly for queryset serialization
- return list(obj)
- if isinstance(obj, Package):
- data = dict((attr, getattr(obj, attr))
- for attr in self.pkg_attributes)
- data['groups'] = obj.groups.all()
- return data
- if isinstance(obj, PackageFile):
- filename = obj.filename or ''
- return obj.directory + filename
- if isinstance(obj, (Repo, Arch, PackageGroup)):
- return obj.name.lower()
- return super(PackageJSONEncoder, self).default(obj)
-
-def opensearch(request):
- if request.is_secure():
- domain = "https://%s" % request.META['HTTP_HOST']
- else:
- domain = "http://%s" % request.META['HTTP_HOST']
-
- return direct_to_template(request, 'packages/opensearch.xml',
- {'domain': domain},
- mimetype='application/opensearchdescription+xml')
-
-@permission_required('main.change_package')
-@require_POST
-def update(request):
- ids = request.POST.getlist('pkgid')
- count = 0
-
- if request.POST.has_key('adopt'):
- repos = request.user.userprofile.allowed_repos.all()
- pkgs = Package.objects.filter(id__in=ids, repo__in=repos)
- disallowed_pkgs = Package.objects.filter(id__in=ids).exclude(
- repo__in=repos)
-
- if disallowed_pkgs:
- messages.warning(request,
- "You do not have permission to adopt: %s." % (
- ' '.join([p.pkgname for p in disallowed_pkgs])
- ))
-
- for pkg in pkgs:
- if request.user not in pkg.maintainers:
- prel = PackageRelation(pkgbase=pkg.pkgbase,
- user=request.user,
- type=PackageRelation.MAINTAINER)
- count += 1
- prel.save()
-
- messages.info(request, "%d base packages adopted." % count)
-
- elif request.POST.has_key('disown'):
- # allow disowning regardless of allowed repos, helps things like
- # [community] -> [extra] moves
- for pkg in Package.objects.filter(id__in=ids):
- if request.user in pkg.maintainers:
- rels = PackageRelation.objects.filter(pkgbase=pkg.pkgbase,
- user=request.user,
- type=PackageRelation.MAINTAINER)
- count += rels.count()
- rels.delete()
-
- messages.info(request, "%d base packages disowned." % count)
-
- else:
- messages.error(request, "Are you trying to adopt or disown?")
- return redirect('/packages/')
-
-def details(request, name='', repo='', arch=''):
- if all([name, repo, arch]):
- try:
- pkg = Package.objects.select_related(
- 'arch', 'repo', 'packager').get(pkgname=name,
- repo__name__iexact=repo, arch__name=arch)
- return direct_to_template(request, 'packages/details.html',
- {'pkg': pkg, })
- except Package.DoesNotExist:
- arch = get_object_or_404(Arch, name=arch)
- arches = [ arch ]
- arches.extend(Arch.objects.filter(agnostic=True))
- repo = get_object_or_404(Repo, name__iexact=repo)
- pkgs = Package.objects.normal().filter(pkgbase=name,
- repo__testing=repo.testing, repo__staging=repo.staging,
- arch__in=arches).order_by('pkgname')
- if len(pkgs) == 0:
- raise Http404
- context = {
- 'list_title': 'Split Package Details',
- 'name': name,
- 'arch': arch,
- 'packages': pkgs,
- }
- return direct_to_template(request, 'packages/packages_list.html',
- context)
- else:
- pkg_data = [
- ('arch', arch.lower()),
- ('repo', repo.lower()),
- ('q', name),
- ]
- # only include non-blank values in the query we generate
- pkg_data = [(x, y) for x, y in pkg_data if y]
- return redirect("/packages/?%s" % urlencode(pkg_data))
-
-def groups(request, arch=None):
- arches = []
- if arch:
- get_object_or_404(Arch, name=arch, agnostic=False)
- arches.append(arch)
- grps = get_group_info(arches)
- context = {
- 'groups': grps,
- 'arch': arch,
- }
- return direct_to_template(request, 'packages/groups.html', context)
-
-def group_details(request, arch, name):
- arch = get_object_or_404(Arch, name=arch)
- arches = [ arch ]
- arches.extend(Arch.objects.filter(agnostic=True))
- pkgs = Package.objects.normal().filter(
- groups__name=name, arch__in=arches).order_by('pkgname')
- if len(pkgs) == 0:
- raise Http404
- context = {
- 'list_title': 'Group Details',
- 'name': name,
- 'arch': arch,
- 'packages': pkgs,
- }
- return direct_to_template(request, 'packages/packages_list.html', context)
-
-def coerce_limit_value(value):
- if not value:
- return None
- if value == 'all':
- # negative value indicates show all results
- return -1
- value = int(value)
- if value < 0:
- raise ValueError
- return value
-
-class LimitTypedChoiceField(forms.TypedChoiceField):
- def valid_value(self, value):
- try:
- coerce_limit_value(value)
- return True
- except (ValueError, TypeError):
- return False
-
-class PackageSearchForm(forms.Form):
- repo = forms.MultipleChoiceField(required=False)
- arch = forms.MultipleChoiceField(required=False)
- q = forms.CharField(required=False)
- maintainer = forms.ChoiceField(required=False)
- packager = forms.ChoiceField(required=False)
- last_update = forms.DateField(required=False, widget=AdminDateWidget(),
- label='Last Updated After')
- flagged = forms.ChoiceField(
- choices=[('', 'All')] + make_choice(['Flagged', 'Not Flagged']),
- required=False)
- limit = LimitTypedChoiceField(
- choices=make_choice([50, 100, 250]) + [('all', 'All')],
- coerce=coerce_limit_value,
- required=False,
- initial=50)
-
- def __init__(self, *args, **kwargs):
- super(PackageSearchForm, self).__init__(*args, **kwargs)
- self.fields['repo'].choices = make_choice(
- [repo.name for repo in Repo.objects.all()])
- self.fields['arch'].choices = make_choice(
- [arch.name for arch in Arch.objects.all()])
- self.fields['q'].widget.attrs.update({"size": "30"})
- maints = User.objects.filter(is_active=True).order_by('username')
- self.fields['maintainer'].choices = \
- [('', 'All'), ('orphan', 'Orphan')] + \
- [(m.username, m.get_full_name()) for m in maints]
- self.fields['packager'].choices = \
- [('', 'All'), ('unknown', 'Unknown')] + \
- [(m.username, m.get_full_name()) for m in maints]
-
-def search(request, page=None):
- limit = 50
- packages = Package.objects.normal()
-
- if request.GET:
- form = PackageSearchForm(data=request.GET)
- if form.is_valid():
- if form.cleaned_data['repo']:
- packages = packages.filter(
- repo__name__in=form.cleaned_data['repo'])
-
- if form.cleaned_data['arch']:
- packages = packages.filter(
- arch__name__in=form.cleaned_data['arch'])
-
- if form.cleaned_data['maintainer'] == 'orphan':
- inner_q = PackageRelation.objects.all().values('pkgbase')
- packages = packages.exclude(pkgbase__in=inner_q)
- elif form.cleaned_data['maintainer']:
- inner_q = PackageRelation.objects.filter(
- user__username=form.cleaned_data['maintainer']).values('pkgbase')
- packages = packages.filter(pkgbase__in=inner_q)
-
- if form.cleaned_data['packager'] == 'unknown':
- packages = packages.filter(packager__isnull=True)
- elif form.cleaned_data['packager']:
- packages = packages.filter(
- packager__username=form.cleaned_data['packager'])
-
- if form.cleaned_data['flagged'] == 'Flagged':
- packages = packages.filter(flag_date__isnull=False)
- elif form.cleaned_data['flagged'] == 'Not Flagged':
- packages = packages.filter(flag_date__isnull=True)
-
- if form.cleaned_data['q']:
- query = form.cleaned_data['q']
- q = Q(pkgname__icontains=query) | Q(pkgdesc__icontains=query)
- packages = packages.filter(q)
- if form.cleaned_data['last_update']:
- lu = form.cleaned_data['last_update']
- packages = packages.filter(last_update__gte=
- datetime(lu.year, lu.month, lu.day, 0, 0))
-
- asked_limit = form.cleaned_data['limit']
- if asked_limit and asked_limit < 0:
- limit = None
- elif asked_limit:
- limit = asked_limit
- else:
- # Form had errors, don't return any results, just the busted form
- packages = Package.objects.none()
- else:
- form = PackageSearchForm()
-
- current_query = request.GET.urlencode()
- page_dict = {
- 'search_form': form,
- 'current_query': current_query
- }
- allowed_sort = ["arch", "repo", "pkgname", "pkgbase",
- "compressed_size", "installed_size",
- "build_date", "last_update", "flag_date"]
- allowed_sort += ["-" + s for s in allowed_sort]
- sort = request.GET.get('sort', None)
- # TODO: sorting by multiple fields makes using a DB index much harder
- if sort in allowed_sort:
- packages = packages.order_by(
- request.GET['sort'], 'repo', 'arch', 'pkgname')
- page_dict['sort'] = sort
- else:
- packages = packages.order_by('pkgname')
-
- return list_detail.object_list(request, packages,
- template_name="packages/search.html",
- page=page,
- paginate_by=limit,
- template_object_name="package",
- extra_context=page_dict)
-
-@vary_on_headers('X-Requested-With')
-def files(request, name, repo, arch):
- pkg = get_object_or_404(Package,
- pkgname=name, repo__name__iexact=repo, arch__name=arch)
- fileslist = PackageFile.objects.filter(pkg=pkg).order_by('directory', 'filename')
- context = {
- 'pkg': pkg,
- 'files': fileslist,
- }
- template = 'packages/files.html'
- if request.is_ajax():
- template = 'packages/files-list.html'
- return direct_to_template(request, template, context)
-
-def details_json(request, name, repo, arch):
- pkg = get_object_or_404(Package,
- pkgname=name, repo__name__iexact=repo, arch__name=arch)
- to_json = simplejson.dumps(pkg, ensure_ascii=False,
- cls=PackageJSONEncoder)
- return HttpResponse(to_json, mimetype='application/json')
-
-def files_json(request, name, repo, arch):
- pkg = get_object_or_404(Package,
- pkgname=name, repo__name__iexact=repo, arch__name=arch)
- fileslist = PackageFile.objects.filter(pkg=pkg).order_by('directory', 'filename')
- data = {
- 'pkgname': pkg.pkgname,
- 'repo': pkg.repo.name.lower(),
- 'arch': pkg.arch.name.lower(),
- 'files': fileslist,
- }
- to_json = simplejson.dumps(data, ensure_ascii=False,
- cls=PackageJSONEncoder)
- return HttpResponse(to_json, mimetype='application/json')
-
-@permission_required('main.change_package')
-def unflag(request, name, repo, arch):
- pkg = get_object_or_404(Package,
- pkgname=name, repo__name__iexact=repo, arch__name=arch)
- pkg.flag_date = None
- pkg.save()
- return redirect(pkg)
-
-@permission_required('main.change_package')
-def unflag_all(request, name, repo, arch):
- pkg = get_object_or_404(Package,
- pkgname=name, repo__name__iexact=repo, arch__name=arch)
- # find all packages from (hopefully) the same PKGBUILD
- pkgs = Package.objects.filter(pkgbase=pkg.pkgbase,
- repo__testing=pkg.repo.testing, repo__staging=pkg.repo.staging)
- pkgs.update(flag_date=None)
- return redirect(pkg)
-
-class PackageSignoffGroup(object):
- '''Encompasses all packages in testing with the same pkgbase.'''
- def __init__(self, packages, target_repo=None, signoffs=None):
- if len(packages) == 0:
- raise Exception
- self.packages = packages
- self.target_repo = target_repo
- self.signoffs = signoffs
-
- first = packages[0]
- self.pkgbase = first.pkgbase
- self.arch = first.arch
- self.repo = first.repo
- self.version = ''
-
- version = first.full_version
- if all(version == pkg.full_version for pkg in packages):
- self.version = version
-
- @property
- def package(self):
- '''Try and return a relevant single package object representing this
- group. Start by seeing if there is only one package, then look for the
- matching package by name, finally falling back to a standin package
- object.'''
- if len(self.packages) == 1:
- return self.packages[0]
-
- same_pkgs = [p for p in self.packages if p.pkgname == p.pkgbase]
- if same_pkgs:
- return same_pkgs[0]
-
- return PackageStandin(self.packages[0])
-
- def find_signoffs(self, all_signoffs):
- '''Look through a list of Signoff objects for ones matching this
- particular group and store them on the object.'''
- if self.signoffs is None:
- self.signoffs = []
- for s in all_signoffs:
- if s.pkgbase != self.pkgbase:
- continue
- if self.version and not s.full_version == self.version:
- continue
- if s.arch_id == self.arch.id and s.repo_id == self.repo.id:
- self.signoffs.append(s)
-
- def approved(self):
- if self.signoffs:
- good_signoffs = [s for s in self.signoffs if not s.revoked]
- return len(good_signoffs) >= Signoff.REQUIRED
- return False
-
-@permission_required('main.change_package')
-@never_cache
-def signoffs(request):
- test_pkgs = Package.objects.normal().filter(repo__testing=True)
- packages = test_pkgs.order_by('pkgname')
-
- # Collect all pkgbase values in testing repos
- q_pkgbase = test_pkgs.values('pkgbase')
- package_repos = Package.objects.order_by().values_list(
- 'pkgbase', 'repo__name').filter(
- repo__testing=False, repo__staging=False,
- pkgbase__in=q_pkgbase).distinct()
- pkgtorepo = dict(package_repos)
-
- # Collect all existing signoffs for these packages
- signoffs = get_current_signoffs()
-
- same_pkgbase_key = lambda x: (x.repo.name, x.arch.name, x.pkgbase)
- grouped = groupby_preserve_order(packages, same_pkgbase_key)
- signoff_groups = []
- for group in grouped:
- signoff_group = PackageSignoffGroup(group)
- signoff_group.target_repo = pkgtorepo.get(signoff_group.pkgbase,
- "Unknown")
- signoff_group.find_signoffs(signoffs)
- signoff_groups.append(signoff_group)
-
- signoff_groups.sort(key=attrgetter('pkgbase'))
-
- return direct_to_template(request, 'packages/signoffs.html',
- {'signoff_groups': signoff_groups})
-
-@permission_required('main.change_package')
-@never_cache
-def signoff_package(request, name, repo, arch):
- packages = get_list_or_404(Package, pkgbase=name,
- arch__name=arch, repo__name__iexact=repo, repo__testing=True)
-
- pkg = packages[0]
- signoff, created = Signoff.objects.get_or_create(
- pkgbase=pkg.pkgbase, pkgver=pkg.pkgver, pkgrel=pkg.pkgrel,
- epoch=pkg.epoch, arch=pkg.arch, repo=pkg.repo, user=request.user)
-
- if request.is_ajax():
- data = {
- 'created': created,
- 'approved': pkg.approved_for_signoff(),
- 'user': str(request.user),
- }
- return HttpResponse(simplejson.dumps(data),
- mimetype='application/json')
-
- return redirect('package-signoffs')
-
-def flaghelp(request):
- return direct_to_template(request, 'packages/flaghelp.html')
-
-class FlagForm(forms.Form):
- email = forms.EmailField(label='* E-mail Address')
- usermessage = forms.CharField(label='Message To Dev',
- widget=forms.Textarea, required=False)
- # The field below is used to filter out bots that blindly fill out all input elements
- website = forms.CharField(label='',
- widget=forms.TextInput(attrs={'style': 'display:none;'}),
- required=False)
-
-@never_cache
-def flag(request, name, repo, arch):
- pkg = get_object_or_404(Package,
- pkgname=name, repo__name__iexact=repo, arch__name=arch)
- if pkg.flag_date is not None:
- # already flagged. do nothing.
- return direct_to_template(request, 'packages/flagged.html', {'pkg': pkg})
- # find all packages from (hopefully) the same PKGBUILD
- pkgs = Package.objects.normal().filter(
- pkgbase=pkg.pkgbase, flag_date__isnull=True,
- repo__testing=pkg.repo.testing,
- repo__staging=pkg.repo.staging).order_by(
- 'pkgname', 'repo__name', 'arch__name')
-
- if request.POST:
- form = FlagForm(request.POST)
- if form.is_valid() and form.cleaned_data['website'] == '':
- # save the package list for later use
- flagged_pkgs = list(pkgs)
- pkgs.update(flag_date=datetime.utcnow())
-
- maints = pkg.maintainers
- if not maints:
- toemail = settings.NOTIFICATIONS
- subject = 'Orphan %s package [%s] marked out-of-date' % \
- (pkg.repo.name, pkg.pkgname)
- else:
- toemail = []
- subject = '%s package [%s] marked out-of-date' % \
- (pkg.repo.name, pkg.pkgname)
- for maint in maints:
- if maint.get_profile().notify == True:
- toemail.append(maint.email)
-
- if toemail:
- # send notification email to the maintainers
- t = loader.get_template('packages/outofdate.txt')
- c = Context({
- 'email': form.cleaned_data['email'],
- 'message': form.cleaned_data['usermessage'],
- 'pkg': pkg,
- 'packages': flagged_pkgs,
- })
- send_mail(subject,
- t.render(c),
- 'Parabola Packages <packages@list.parabolagnulinux.org>',
- toemail,
- fail_silently=True)
-
- return redirect('package-flag-confirmed', name=name, repo=repo,
- arch=arch)
- else:
- form = FlagForm()
-
- context = {
- 'package': pkg,
- 'packages': pkgs,
- 'form': form
- }
- return direct_to_template(request, 'packages/flag.html', context)
-
-def flag_confirmed(request, name, repo, arch):
- pkg = get_object_or_404(Package,
- pkgname=name, repo__name__iexact=repo, arch__name=arch)
- pkgs = Package.objects.normal().filter(
- pkgbase=pkg.pkgbase, flag_date=pkg.flag_date,
- repo__testing=pkg.repo.testing,
- repo__staging=pkg.repo.staging).order_by(
- 'pkgname', 'repo__name', 'arch__name')
-
- context = {'package': pkg, 'packages': pkgs}
-
- return direct_to_template(request, 'packages/flag_confirmed.html', context)
-
-def download(request, name, repo, arch):
- pkg = get_object_or_404(Package,
- pkgname=name, repo__name__iexact=repo, arch__name=arch)
- mirrorurl = MirrorUrl.objects.filter(mirror__country='Any',
- mirror__public=True, mirror__active=True,
- protocol__protocol__iexact='HTTP')[0]
- arch = pkg.arch.name
- if pkg.arch.agnostic:
- # grab the first non-any arch to fake the download path
- arch = Arch.objects.exclude(agnostic=True)[0].name
- values = {
- 'host': mirrorurl.url,
- 'arch': arch,
- 'repo': pkg.repo.name.lower(),
- 'file': pkg.filename,
- }
- url = string.Template('${host}${repo}/os/${arch}/${file}').substitute(values)
- return redirect(url)
-
-def arch_differences(request):
- # TODO: we have some hardcoded magic here with respect to the arches.
- arch_a = Arch.objects.get(name='i686')
- arch_b = Arch.objects.get(name='x86_64')
- differences = get_differences_info(arch_a, arch_b)
- context = {
- 'arch_a': arch_a,
- 'arch_b': arch_b,
- 'differences': differences,
- }
- return direct_to_template(request, 'packages/differences.html', context)
-
-@permission_required('main.change_package')
-@never_cache
-def stale_relations(request):
- relations = PackageRelation.objects.select_related('user')
- pkgbases = Package.objects.all().values('pkgbase')
-
- inactive_user = relations.filter(user__is_active=False)
- missing_pkgbase = relations.exclude(
- pkgbase__in=pkgbases).order_by('pkgbase')
- wrong_permissions = get_wrong_permissions()
-
- context = {
- 'inactive_user': inactive_user,
- 'missing_pkgbase': missing_pkgbase,
- 'wrong_permissions': wrong_permissions,
- }
- return direct_to_template(request, 'packages/stale_relations.html', context)
-
-@permission_required('packages.delete_packagerelation')
-@require_POST
-def stale_relations_update(request):
- ids = set(request.POST.getlist('relation_id'))
-
- if ids:
- PackageRelation.objects.filter(id__in=ids).delete()
-
- messages.info(request, "%d package relations deleted." % len(ids))
- return redirect('/packages/stale_relations/')
-
-# vim: set ts=4 sw=4 et:
diff --git a/packages/views/__init__.py b/packages/views/__init__.py
new file mode 100644
index 00000000..e3264161
--- /dev/null
+++ b/packages/views/__init__.py
@@ -0,0 +1,268 @@
+from django.contrib import messages
+from django.contrib.auth.decorators import permission_required
+from django.core.serializers.json import DjangoJSONEncoder
+from django.http import HttpResponse, Http404
+from django.shortcuts import get_object_or_404, redirect
+from django.utils import simplejson
+from django.views.decorators.cache import never_cache
+from django.views.decorators.http import require_POST
+from django.views.decorators.vary import vary_on_headers
+from django.views.generic.simple import direct_to_template
+
+from string import Template
+from urllib import urlencode
+
+from main.models import Package, PackageFile, Arch, Repo
+from mirrors.models import MirrorUrl
+from ..models import PackageRelation, PackageGroup
+from ..utils import (get_group_info, get_differences_info,
+ get_wrong_permissions)
+
+# make other views available from this same package
+from .flag import flaghelp, flag, flag_confirmed, unflag, unflag_all
+from .search import search
+from .signoff import signoffs, signoff_package, signoff_options, signoffs_json
+
+
+class PackageJSONEncoder(DjangoJSONEncoder):
+ pkg_attributes = [ 'pkgname', 'pkgbase', 'repo', 'arch', 'pkgver',
+ 'pkgrel', 'epoch', 'pkgdesc', 'url', 'filename', 'compressed_size',
+ 'installed_size', 'build_date', 'last_update', 'flag_date' ]
+
+ def default(self, obj):
+ if hasattr(obj, '__iter__'):
+ # mainly for queryset serialization
+ return list(obj)
+ if isinstance(obj, Package):
+ data = dict((attr, getattr(obj, attr))
+ for attr in self.pkg_attributes)
+ data['groups'] = obj.groups.all()
+ return data
+ if isinstance(obj, PackageFile):
+ filename = obj.filename or ''
+ return obj.directory + filename
+ if isinstance(obj, (Repo, Arch, PackageGroup)):
+ return obj.name.lower()
+ return super(PackageJSONEncoder, self).default(obj)
+
+def opensearch(request):
+ if request.is_secure():
+ domain = "https://%s" % request.META['HTTP_HOST']
+ else:
+ domain = "http://%s" % request.META['HTTP_HOST']
+
+ return direct_to_template(request, 'packages/opensearch.xml',
+ {'domain': domain},
+ mimetype='application/opensearchdescription+xml')
+
+@permission_required('main.change_package')
+@require_POST
+def update(request):
+ ids = request.POST.getlist('pkgid')
+ count = 0
+
+ if request.POST.has_key('adopt'):
+ repos = request.user.userprofile.allowed_repos.all()
+ pkgs = Package.objects.filter(id__in=ids, repo__in=repos)
+ disallowed_pkgs = Package.objects.filter(id__in=ids).exclude(
+ repo__in=repos)
+
+ if disallowed_pkgs:
+ messages.warning(request,
+ "You do not have permission to adopt: %s." % (
+ ' '.join([p.pkgname for p in disallowed_pkgs])
+ ))
+
+ for pkg in pkgs:
+ if request.user not in pkg.maintainers:
+ prel = PackageRelation(pkgbase=pkg.pkgbase,
+ user=request.user,
+ type=PackageRelation.MAINTAINER)
+ count += 1
+ prel.save()
+
+ messages.info(request, "%d base packages adopted." % count)
+
+ elif request.POST.has_key('disown'):
+ # allow disowning regardless of allowed repos, helps things like
+ # [community] -> [extra] moves
+ for pkg in Package.objects.filter(id__in=ids):
+ if request.user in pkg.maintainers:
+ rels = PackageRelation.objects.filter(pkgbase=pkg.pkgbase,
+ user=request.user,
+ type=PackageRelation.MAINTAINER)
+ count += rels.count()
+ rels.delete()
+
+ messages.info(request, "%d base packages disowned." % count)
+
+ else:
+ messages.error(request, "Are you trying to adopt or disown?")
+ return redirect('/packages/')
+
+def details(request, name='', repo='', arch=''):
+ if all([name, repo, arch]):
+ try:
+ pkg = Package.objects.select_related(
+ 'arch', 'repo', 'packager').get(pkgname=name,
+ repo__name__iexact=repo, arch__name=arch)
+ return direct_to_template(request, 'packages/details.html',
+ {'pkg': pkg, })
+ except Package.DoesNotExist:
+ arch = get_object_or_404(Arch, name=arch)
+ arches = [ arch ]
+ arches.extend(Arch.objects.filter(agnostic=True))
+ repo = get_object_or_404(Repo, name__iexact=repo)
+ pkgs = Package.objects.normal().filter(pkgbase=name,
+ repo__testing=repo.testing, repo__staging=repo.staging,
+ arch__in=arches).order_by('pkgname')
+ if len(pkgs) == 0:
+ raise Http404
+ context = {
+ 'list_title': 'Split Package Details',
+ 'name': name,
+ 'arch': arch,
+ 'packages': pkgs,
+ }
+ return direct_to_template(request, 'packages/packages_list.html',
+ context)
+ else:
+ pkg_data = [
+ ('arch', arch.lower()),
+ ('repo', repo.lower()),
+ ('q', name),
+ ]
+ # only include non-blank values in the query we generate
+ pkg_data = [(x, y) for x, y in pkg_data if y]
+ return redirect("/packages/?%s" % urlencode(pkg_data))
+
+def groups(request, arch=None):
+ arches = []
+ if arch:
+ get_object_or_404(Arch, name=arch, agnostic=False)
+ arches.append(arch)
+ grps = get_group_info(arches)
+ context = {
+ 'groups': grps,
+ 'arch': arch,
+ }
+ return direct_to_template(request, 'packages/groups.html', context)
+
+def group_details(request, arch, name):
+ arch = get_object_or_404(Arch, name=arch)
+ arches = [ arch ]
+ arches.extend(Arch.objects.filter(agnostic=True))
+ pkgs = Package.objects.normal().filter(
+ groups__name=name, arch__in=arches).order_by('pkgname')
+ if len(pkgs) == 0:
+ raise Http404
+ context = {
+ 'list_title': 'Group Details',
+ 'name': name,
+ 'arch': arch,
+ 'packages': pkgs,
+ }
+ return direct_to_template(request, 'packages/packages_list.html', context)
+
+@vary_on_headers('X-Requested-With')
+def files(request, name, repo, arch):
+ pkg = get_object_or_404(Package,
+ pkgname=name, repo__name__iexact=repo, arch__name=arch)
+ fileslist = PackageFile.objects.filter(pkg=pkg).order_by('directory', 'filename')
+ context = {
+ 'pkg': pkg,
+ 'files': fileslist,
+ }
+ template = 'packages/files.html'
+ if request.is_ajax():
+ template = 'packages/files-list.html'
+ return direct_to_template(request, template, context)
+
+def details_json(request, name, repo, arch):
+ pkg = get_object_or_404(Package,
+ pkgname=name, repo__name__iexact=repo, arch__name=arch)
+ to_json = simplejson.dumps(pkg, ensure_ascii=False,
+ cls=PackageJSONEncoder)
+ return HttpResponse(to_json, mimetype='application/json')
+
+def files_json(request, name, repo, arch):
+ pkg = get_object_or_404(Package,
+ pkgname=name, repo__name__iexact=repo, arch__name=arch)
+ fileslist = PackageFile.objects.filter(pkg=pkg).order_by('directory', 'filename')
+ data = {
+ 'pkgname': pkg.pkgname,
+ 'repo': pkg.repo.name.lower(),
+ 'arch': pkg.arch.name.lower(),
+ 'files': fileslist,
+ }
+ to_json = simplejson.dumps(data, ensure_ascii=False,
+ cls=PackageJSONEncoder)
+ return HttpResponse(to_json, mimetype='application/json')
+
+def download(request, name, repo, arch):
+ pkg = get_object_or_404(Package,
+ pkgname=name, repo__name__iexact=repo, arch__name=arch)
+ mirror_urls = MirrorUrl.objects.filter(
+ mirror__public=True, mirror__active=True,
+ protocol__protocol__iexact='HTTP')
+ # look first for an 'Any' URL, then fall back to any HTTP URL
+ filtered_urls = mirror_urls.filter(mirror__country='Any')[:1]
+ if not filtered_urls:
+ filtered_urls = mirror_urls[:1]
+ if not filtered_urls:
+ raise Http404
+ arch = pkg.arch.name
+ if pkg.arch.agnostic:
+ # grab the first non-any arch to fake the download path
+ arch = Arch.objects.exclude(agnostic=True)[0].name
+ values = {
+ 'host': filtered_urls[0].url,
+ 'arch': arch,
+ 'repo': pkg.repo.name.lower(),
+ 'file': pkg.filename,
+ }
+ url = Template('${host}${repo}/os/${arch}/${file}').substitute(values)
+ return redirect(url)
+
+def arch_differences(request):
+ # TODO: we have some hardcoded magic here with respect to the arches.
+ arch_a = Arch.objects.get(name='i686')
+ arch_b = Arch.objects.get(name='x86_64')
+ differences = get_differences_info(arch_a, arch_b)
+ context = {
+ 'arch_a': arch_a,
+ 'arch_b': arch_b,
+ 'differences': differences,
+ }
+ return direct_to_template(request, 'packages/differences.html', context)
+
+@permission_required('main.change_package')
+@never_cache
+def stale_relations(request):
+ relations = PackageRelation.objects.select_related('user')
+ pkgbases = Package.objects.all().values('pkgbase')
+
+ inactive_user = relations.filter(user__is_active=False)
+ missing_pkgbase = relations.exclude(
+ pkgbase__in=pkgbases).order_by('pkgbase')
+ wrong_permissions = get_wrong_permissions()
+
+ context = {
+ 'inactive_user': inactive_user,
+ 'missing_pkgbase': missing_pkgbase,
+ 'wrong_permissions': wrong_permissions,
+ }
+ return direct_to_template(request, 'packages/stale_relations.html', context)
+
+@permission_required('packages.delete_packagerelation')
+@require_POST
+def stale_relations_update(request):
+ ids = set(request.POST.getlist('relation_id'))
+
+ if ids:
+ PackageRelation.objects.filter(id__in=ids).delete()
+
+ messages.info(request, "%d package relations deleted." % len(ids))
+ return redirect('/packages/stale_relations/')
+
+# vim: set ts=4 sw=4 et:
diff --git a/packages/views/flag.py b/packages/views/flag.py
new file mode 100644
index 00000000..7e9d87c7
--- /dev/null
+++ b/packages/views/flag.py
@@ -0,0 +1,121 @@
+from datetime import datetime
+
+from django import forms
+from django.conf import settings
+from django.contrib.auth.decorators import permission_required
+from django.core.mail import send_mail
+from django.shortcuts import get_object_or_404, redirect
+from django.template import loader, Context
+from django.views.generic.simple import direct_to_template
+from django.views.decorators.cache import never_cache
+
+from main.models import Package
+
+
+def flaghelp(request):
+ return direct_to_template(request, 'packages/flaghelp.html')
+
+class FlagForm(forms.Form):
+ email = forms.EmailField(label='* E-mail Address')
+ usermessage = forms.CharField(label='Message To Dev',
+ widget=forms.Textarea, required=False)
+ # The field below is used to filter out bots that blindly fill out all
+ # input elements
+ website = forms.CharField(label='',
+ widget=forms.TextInput(attrs={'style': 'display:none;'}),
+ required=False)
+
+@never_cache
+def flag(request, name, repo, arch):
+ pkg = get_object_or_404(Package,
+ pkgname=name, repo__name__iexact=repo, arch__name=arch)
+ if pkg.flag_date is not None:
+ # already flagged. do nothing.
+ return direct_to_template(request, 'packages/flagged.html',
+ {'pkg': pkg})
+ # find all packages from (hopefully) the same PKGBUILD
+ pkgs = Package.objects.normal().filter(
+ pkgbase=pkg.pkgbase, flag_date__isnull=True,
+ repo__testing=pkg.repo.testing,
+ repo__staging=pkg.repo.staging).order_by(
+ 'pkgname', 'repo__name', 'arch__name')
+
+ if request.POST:
+ form = FlagForm(request.POST)
+ if form.is_valid() and form.cleaned_data['website'] == '':
+ # save the package list for later use
+ flagged_pkgs = list(pkgs)
+ pkgs.update(flag_date=datetime.utcnow())
+
+ maints = pkg.maintainers
+ if not maints:
+ toemail = settings.NOTIFICATIONS
+ subject = 'Orphan %s package [%s] marked out-of-date' % \
+ (pkg.repo.name, pkg.pkgname)
+ else:
+ toemail = []
+ subject = '%s package [%s] marked out-of-date' % \
+ (pkg.repo.name, pkg.pkgname)
+ for maint in maints:
+ if maint.get_profile().notify == True:
+ toemail.append(maint.email)
+
+ if toemail:
+ # send notification email to the maintainers
+ tmpl = loader.get_template('packages/outofdate.txt')
+ ctx = Context({
+ 'email': form.cleaned_data['email'],
+ 'message': form.cleaned_data['usermessage'],
+ 'pkg': pkg,
+ 'packages': flagged_pkgs,
+ })
+ send_mail(subject,
+ tmpl.render(ctx),
+ 'Arch Website Notification <nobody@archlinux.org>',
+ toemail,
+ fail_silently=True)
+
+ return redirect('package-flag-confirmed', name=name, repo=repo,
+ arch=arch)
+ else:
+ form = FlagForm()
+
+ context = {
+ 'package': pkg,
+ 'packages': pkgs,
+ 'form': form
+ }
+ return direct_to_template(request, 'packages/flag.html', context)
+
+def flag_confirmed(request, name, repo, arch):
+ pkg = get_object_or_404(Package,
+ pkgname=name, repo__name__iexact=repo, arch__name=arch)
+ pkgs = Package.objects.normal().filter(
+ pkgbase=pkg.pkgbase, flag_date=pkg.flag_date,
+ repo__testing=pkg.repo.testing,
+ repo__staging=pkg.repo.staging).order_by(
+ 'pkgname', 'repo__name', 'arch__name')
+
+ context = {'package': pkg, 'packages': pkgs}
+
+ return direct_to_template(request, 'packages/flag_confirmed.html', context)
+
+@permission_required('main.change_package')
+def unflag(request, name, repo, arch):
+ pkg = get_object_or_404(Package,
+ pkgname=name, repo__name__iexact=repo, arch__name=arch)
+ pkg.flag_date = None
+ pkg.save()
+ return redirect(pkg)
+
+@permission_required('main.change_package')
+def unflag_all(request, name, repo, arch):
+ pkg = get_object_or_404(Package,
+ pkgname=name, repo__name__iexact=repo, arch__name=arch)
+ # find all packages from (hopefully) the same PKGBUILD
+ pkgs = Package.objects.filter(pkgbase=pkg.pkgbase,
+ repo__testing=pkg.repo.testing, repo__staging=pkg.repo.staging)
+ pkgs.update(flag_date=None)
+ return redirect(pkg)
+
+# vim: set ts=4 sw=4 et:
diff --git a/packages/views/search.py b/packages/views/search.py
new file mode 100644
index 00000000..65fcddb3
--- /dev/null
+++ b/packages/views/search.py
@@ -0,0 +1,168 @@
+from datetime import datetime
+
+from django import forms
+from django.contrib.admin.widgets import AdminDateWidget
+from django.contrib.auth.models import User
+from django.db.models import Q
+from django.views.generic import list_detail
+
+from main.models import Package, Arch, Repo
+from main.utils import make_choice
+from ..models import PackageRelation
+
+
+def coerce_limit_value(value):
+ if not value:
+ return None
+ if value == 'all':
+ # negative value indicates show all results
+ return -1
+ value = int(value)
+ if value < 0:
+ raise ValueError
+ return value
+
+class LimitTypedChoiceField(forms.TypedChoiceField):
+ def valid_value(self, value):
+ try:
+ coerce_limit_value(value)
+ return True
+ except (ValueError, TypeError):
+ return False
+
+class PackageSearchForm(forms.Form):
+ repo = forms.MultipleChoiceField(required=False)
+ arch = forms.MultipleChoiceField(required=False)
+ name = forms.CharField(required=False)
+ desc = forms.CharField(required=False)
+ q = forms.CharField(required=False)
+ sort = forms.CharField(required=False)
+ maintainer = forms.ChoiceField(required=False)
+ packager = forms.ChoiceField(required=False)
+ last_update = forms.DateField(required=False, widget=AdminDateWidget(),
+ label='Last Updated After')
+ flagged = forms.ChoiceField(
+ choices=[('', 'All')] + make_choice(['Flagged', 'Not Flagged']),
+ required=False)
+ signed = forms.ChoiceField(
+ choices=[('', 'All')] + make_choice(['Signed', 'Unsigned']),
+ required=False)
+ limit = LimitTypedChoiceField(
+ choices=make_choice([50, 100, 250]) + [('all', 'All')],
+ coerce=coerce_limit_value,
+ required=False,
+ initial=50)
+
+ def __init__(self, *args, **kwargs):
+ super(PackageSearchForm, self).__init__(*args, **kwargs)
+ self.fields['repo'].choices = make_choice(
+ [repo.name for repo in Repo.objects.all()])
+ self.fields['arch'].choices = make_choice(
+ [arch.name for arch in Arch.objects.all()])
+ self.fields['q'].widget.attrs.update({"size": "30"})
+ maints = User.objects.filter(is_active=True).order_by(
+ 'first_name', 'last_name')
+ self.fields['maintainer'].choices = \
+ [('', 'All'), ('orphan', 'Orphan')] + \
+ [(m.username, m.get_full_name()) for m in maints]
+ self.fields['packager'].choices = \
+ [('', 'All'), ('unknown', 'Unknown')] + \
+ [(m.username, m.get_full_name()) for m in maints]
+
+def parse_form(form, packages):
+ if form.cleaned_data['repo']:
+ packages = packages.filter(
+ repo__name__in=form.cleaned_data['repo'])
+
+ if form.cleaned_data['arch']:
+ packages = packages.filter(
+ arch__name__in=form.cleaned_data['arch'])
+
+ if form.cleaned_data['maintainer'] == 'orphan':
+ inner_q = PackageRelation.objects.all().values('pkgbase')
+ packages = packages.exclude(pkgbase__in=inner_q)
+ elif form.cleaned_data['maintainer']:
+ inner_q = PackageRelation.objects.filter(
+ user__username=form.cleaned_data['maintainer']).values('pkgbase')
+ packages = packages.filter(pkgbase__in=inner_q)
+
+ if form.cleaned_data['packager'] == 'unknown':
+ packages = packages.filter(packager__isnull=True)
+ elif form.cleaned_data['packager']:
+ packages = packages.filter(
+ packager__username=form.cleaned_data['packager'])
+
+ if form.cleaned_data['flagged'] == 'Flagged':
+ packages = packages.filter(flag_date__isnull=False)
+ elif form.cleaned_data['flagged'] == 'Not Flagged':
+ packages = packages.filter(flag_date__isnull=True)
+
+ if form.cleaned_data['signed'] == 'Signed':
+ packages = packages.filter(pgp_signature__isnull=False)
+ elif form.cleaned_data['signed'] == 'Unsigned':
+ packages = packages.filter(pgp_signature__isnull=True)
+
+ if form.cleaned_data['last_update']:
+ lu = form.cleaned_data['last_update']
+ packages = packages.filter(last_update__gte=
+ datetime(lu.year, lu.month, lu.day, 0, 0))
+
+ if form.cleaned_data['name']:
+ name = form.cleaned_data['name']
+ packages = packages.filter(pkgname__icontains=name)
+
+ if form.cleaned_data['desc']:
+ desc = form.cleaned_data['desc']
+ packages = packages.filter(pkgdesc__icontains=desc)
+
+ if form.cleaned_data['q']:
+ query = form.cleaned_data['q']
+ q = Q(pkgname__icontains=query) | Q(pkgdesc__icontains=query)
+ packages = packages.filter(q)
+
+ return packages
+
+def search(request, page=None):
+ limit = 50
+ sort = None
+ packages = Package.objects.normal()
+
+ if request.GET:
+ form = PackageSearchForm(data=request.GET)
+ if form.is_valid():
+ packages = parse_form(form, packages)
+ asked_limit = form.cleaned_data['limit']
+ if asked_limit and asked_limit < 0:
+ limit = None
+ elif asked_limit:
+ limit = asked_limit
+ sort = form.cleaned_data['sort']
+ else:
+ # Form had errors, don't return any results, just the busted form
+ packages = Package.objects.none()
+ else:
+ form = PackageSearchForm()
+
+ current_query = request.GET.urlencode()
+ page_dict = {
+ 'search_form': form,
+ 'current_query': current_query
+ }
+ allowed_sort = ["arch", "repo", "pkgname", "pkgbase",
+ "compressed_size", "installed_size",
+ "build_date", "last_update", "flag_date"]
+ allowed_sort += ["-" + s for s in allowed_sort]
+ if sort in allowed_sort:
+ packages = packages.order_by(sort)
+ page_dict['sort'] = sort
+ else:
+ packages = packages.order_by('pkgname')
+
+ return list_detail.object_list(request, packages,
+ template_name="packages/search.html",
+ page=page,
+ paginate_by=limit,
+ template_object_name="package",
+ extra_context=page_dict)
+
+# vim: set ts=4 sw=4 et:
diff --git a/packages/views/signoff.py b/packages/views/signoff.py
new file mode 100644
index 00000000..e57b4d9a
--- /dev/null
+++ b/packages/views/signoff.py
@@ -0,0 +1,193 @@
+from datetime import datetime
+from operator import attrgetter
+
+from django import forms
+from django.contrib.auth.decorators import permission_required
+from django.contrib.auth.models import User
+from django.core.serializers.json import DjangoJSONEncoder
+from django.db import transaction
+from django.http import HttpResponse, Http404
+from django.shortcuts import get_list_or_404, redirect, render
+from django.utils import simplejson
+from django.views.decorators.cache import never_cache
+from django.views.generic.simple import direct_to_template
+
+from main.models import Package, Arch, Repo
+from ..models import SignoffSpecification, Signoff
+from ..utils import (get_signoff_groups, approved_by_signoffs,
+ PackageSignoffGroup)
+
+@permission_required('main.change_package')
+@never_cache
+def signoffs(request):
+ signoff_groups = sorted(get_signoff_groups(), key=attrgetter('pkgbase'))
+ for group in signoff_groups:
+ group.user = request.user
+
+ context = {
+ 'signoff_groups': signoff_groups,
+ 'arches': Arch.objects.all(),
+ 'repo_names': sorted(set(g.target_repo for g in signoff_groups)),
+ }
+ return direct_to_template(request, 'packages/signoffs.html', context)
+
+@permission_required('main.change_package')
+@never_cache
+def signoff_package(request, name, repo, arch, revoke=False):
+ packages = get_list_or_404(Package, pkgbase=name,
+ arch__name=arch, repo__name__iexact=repo, repo__testing=True)
+ package = packages[0]
+
+ spec = SignoffSpecification.objects.get_or_default_from_package(package)
+
+ if revoke:
+ try:
+ signoff = Signoff.objects.get_from_package(
+ package, request.user, False)
+ except Signoff.DoesNotExist:
+ raise Http404
+ signoff.revoked = datetime.utcnow()
+ signoff.save()
+ created = False
+ else:
+ # ensure we should even be accepting signoffs
+ if spec.known_bad or not spec.enabled:
+ return render(request, '403.html', status=403)
+ signoff, created = Signoff.objects.get_or_create_from_package(
+ package, request.user)
+
+ all_signoffs = Signoff.objects.for_package(package)
+
+ if request.is_ajax():
+ data = {
+ 'created': created,
+ 'revoked': bool(signoff.revoked),
+ 'approved': approved_by_signoffs(all_signoffs, spec),
+ 'required': spec.required,
+ 'enabled': spec.enabled,
+ 'known_bad': spec.known_bad,
+ 'user': str(request.user),
+ }
+ return HttpResponse(simplejson.dumps(data, ensure_ascii=False),
+ mimetype='application/json')
+
+ return redirect('package-signoffs')
+
+class SignoffOptionsForm(forms.ModelForm):
+ apply_all = forms.BooleanField(required=False,
+ help_text="Apply these options to all architectures?")
+
+ class Meta:
+ model = SignoffSpecification
+ fields = ('required', 'enabled', 'known_bad', 'comments')
+
+def _signoff_options_all(request, name, repo):
+ seen_ids = set()
+ with transaction.commit_on_success():
+ # find or create a specification for all architectures, then
+ # graft the form data onto them
+ packages = Package.objects.filter(pkgbase=name,
+ repo__name__iexact=repo, repo__testing=True)
+ for package in packages:
+ try:
+ spec = SignoffSpecification.objects.get_from_package(package)
+ if spec.pk in seen_ids:
+ continue
+ except SignoffSpecification.DoesNotExist:
+ spec = SignoffSpecification(pkgbase=package.pkgbase,
+ pkgver=package.pkgver, pkgrel=package.pkgrel,
+ epoch=package.epoch, arch=package.arch,
+ repo=package.repo)
+
+ if spec.user is None:
+ spec.user = request.user
+
+ form = SignoffOptionsForm(request.POST, instance=spec)
+ if form.is_valid():
+ form.save()
+ seen_ids.add(form.instance.pk)
+
+@permission_required('main.change_package')
+@never_cache
+def signoff_options(request, name, repo, arch):
+ packages = get_list_or_404(Package, pkgbase=name,
+ arch__name=arch, repo__name__iexact=repo, repo__testing=True)
+ package = packages[0]
+
+ if request.user != package.packager and \
+ request.user not in package.maintainers:
+ return render(request, '403.html', status=403)
+
+ try:
+ spec = SignoffSpecification.objects.get_from_package(package)
+ except SignoffSpecification.DoesNotExist:
+ # create a fake one, but don't save it just yet
+ spec = SignoffSpecification(pkgbase=package.pkgbase,
+ pkgver=package.pkgver, pkgrel=package.pkgrel,
+ epoch=package.epoch, arch=package.arch, repo=package.repo)
+
+ if spec.user is None:
+ spec.user = request.user
+
+ if request.POST:
+ form = SignoffOptionsForm(request.POST, instance=spec)
+ if form.is_valid():
+ if form.cleaned_data['apply_all']:
+ _signoff_options_all(request, name, repo)
+ else:
+ form.save()
+ return redirect('package-signoffs')
+ else:
+ form = SignoffOptionsForm(instance=spec)
+
+ context = {
+ 'packages': packages,
+ 'package': package,
+ 'form': form,
+ }
+ return direct_to_template(request, 'packages/signoff_options.html', context)
+
+class SignoffJSONEncoder(DjangoJSONEncoder):
+ '''Base JSONEncoder extended to handle all serialization of all classes
+ related to signoffs.'''
+ signoff_group_attrs = ['arch', 'last_update', 'maintainers', 'packager',
+ 'pkgbase', 'repo', 'signoffs', 'target_repo', 'version']
+ signoff_spec_attrs = ['required', 'enabled', 'known_bad', 'comments']
+ signoff_attrs = ['user', 'created', 'revoked']
+
+ def default(self, obj):
+ if isinstance(obj, PackageSignoffGroup):
+ data = dict((attr, getattr(obj, attr))
+ for attr in self.signoff_group_attrs)
+ data['pkgnames'] = [p.pkgname for p in obj.packages]
+ data['package_count'] = len(obj.packages)
+ data['approved'] = obj.approved()
+ data.update((attr, getattr(obj.specification, attr))
+ for attr in self.signoff_spec_attrs)
+ return data
+ elif isinstance(obj, Signoff):
+ data = dict((attr, getattr(obj, attr))
+ for attr in self.signoff_attrs)
+ return data
+ elif isinstance(obj, Arch) or isinstance(obj, Repo):
+ return unicode(obj)
+ elif isinstance(obj, User):
+ return obj.username
+ elif isinstance(obj, set):
+ return list(obj)
+ return super(SignoffJSONEncoder, self).default(obj)
+
+@permission_required('main.change_package')
+@never_cache
+def signoffs_json(request):
+ signoff_groups = sorted(get_signoff_groups(), key=attrgetter('pkgbase'))
+ data = {
+ 'version': 1,
+ 'signoff_groups': signoff_groups,
+ }
+ to_json = simplejson.dumps(data, ensure_ascii=False,
+ cls=SignoffJSONEncoder)
+ response = HttpResponse(to_json, mimetype='application/json')
+ return response
+
+# vim: set ts=4 sw=4 et: