diff options
Diffstat (limited to 'main/models.py')
-rw-r--r-- | main/models.py | 36 |
1 files changed, 23 insertions, 13 deletions
diff --git a/main/models.py b/main/models.py index 2ace0109..8d9d4c89 100644 --- a/main/models.py +++ b/main/models.py @@ -1,4 +1,3 @@ -from base64 import b64decode from datetime import datetime from itertools import groupby from pgpdump import BinaryData @@ -9,7 +8,7 @@ from django.contrib.auth.models import User from django.contrib.sites.models import Site from .fields import PositiveBigIntegerField -from .utils import set_created_field +from .utils import set_created_field, DependStandin from devel.models import DeveloperKey from packages.alpm import AlpmAPI @@ -97,7 +96,7 @@ class Package(models.Model): pkgver = models.CharField(max_length=255) pkgrel = models.CharField(max_length=255) epoch = models.PositiveIntegerField(default=0) - pkgdesc = models.TextField(null=True) + pkgdesc = models.TextField('description', null=True) url = models.CharField(max_length=255, null=True) filename = models.CharField(max_length=255) compressed_size = PositiveBigIntegerField() @@ -106,10 +105,10 @@ class Package(models.Model): last_update = models.DateTimeField(db_index=True) files_last_update = models.DateTimeField(null=True, blank=True) created = models.DateTimeField() - packager_str = models.CharField(max_length=255) + packager_str = models.CharField('packager string', max_length=255) packager = models.ForeignKey(User, null=True, blank=True, on_delete=models.SET_NULL) - pgp_signature = models.TextField(null=True, blank=True) + signature_bytes = models.BinaryField('PGP signature', null=True) flag_date = models.DateTimeField(null=True, blank=True) objects = PackageManager() @@ -140,13 +139,9 @@ class Package(models.Model): @property def signature(self): - try: - data = b64decode(self.pgp_signature.encode('utf-8')) - except TypeError: - return None - if not data: + if not self.signature_bytes: return None - data = BinaryData(data) + data = BinaryData(self.signature_bytes) packets = list(data.packets()) return packets[0] @@ -247,6 +242,20 @@ class Package(models.Model): if len(requiredby) == 0: return requiredby + # do we have duplicate pkgbase values for non-primary depends? + # if so, filter it down to base packages only + def grouper(depend): + p = depend.pkg + return (depend.deptype, p.pkgbase, p.repo.testing, p.repo.staging) + + filtered = [] + for (typ, pkgbase, _, _), dep_pkgs in groupby(requiredby, grouper): + dep_pkgs = list(dep_pkgs) + if typ == 'D' or len(dep_pkgs) == 1: + filtered.extend(dep_pkgs) + else: + filtered.append(DependStandin(dep_pkgs)) + # find another package by this name in a different testing or staging # repo; if we can't, we can short-circuit some checks repo_q = (Q(repo__testing=(not self.repo.testing)) | @@ -255,13 +264,13 @@ class Package(models.Model): repo_q, pkgname=self.pkgname, arch=self.arch ).exclude(id=self.id).exists(): # there isn't one? short circuit, all required by entries are fine - return requiredby + return filtered trimmed = [] # for each unique package name, try to screen our package list down to # those packages in the same testing and staging category (yes or no) # iff there is a package in the same testing and staging category. - for _, dep_pkgs in groupby(requiredby, lambda x: x.pkg.pkgname): + for _, dep_pkgs in groupby(filtered, lambda x: x.pkg.pkgname): dep_pkgs = list(dep_pkgs) dep = dep_pkgs[0] if len(dep_pkgs) > 1: @@ -271,6 +280,7 @@ class Package(models.Model): if len(dep_pkgs) > 0: dep = dep_pkgs[0] trimmed.append(dep) + return trimmed def get_depends(self): |