summaryrefslogtreecommitdiffstats
path: root/packages
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2012-05-19 04:29:03 +0200
committerDan McGee <dan@archlinux.org>2012-05-19 04:36:11 +0200
commit72a92102df4999dbcc370064707c9026d51c4fe7 (patch)
tree7fe5be4bb93cb677952923899b954cc59e1b5e11 /packages
parentcc44fdbea59596daf106e48acdb3f4137988d0d9 (diff)
downloadarchweb-72a92102df4999dbcc370064707c9026d51c4fe7.tar.gz
archweb-72a92102df4999dbcc370064707c9026d51c4fe7.tar.xz
Switch to usage of new Depend object
Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'packages')
-rw-r--r--packages/models.py34
-rw-r--r--packages/utils.py6
2 files changed, 33 insertions, 7 deletions
diff --git a/packages/models.py b/packages/models.py
index c7b1cab..cb65f1f 100644
--- a/packages/models.py
+++ b/packages/models.py
@@ -228,10 +228,6 @@ class RelatedToBase(models.Model):
'''Find a satisfier for this related package that best matches the
given criteria. It will not search provisions, but will find packages
named and matching repo characteristics if possible.'''
- # NOTE: this is cribbed directly from the PackageDepend method of the
- # same name. Really, all of these things could use the same method if
- # the PackageDepend class was moved here and field names were changed
- # to match the layout we use here.
pkgs = Package.objects.normal().filter(pkgname=self.name)
if not self.pkg.arch.agnostic:
# make sure we match architectures if possible
@@ -258,6 +254,36 @@ class RelatedToBase(models.Model):
return pkg
+ def get_providers(self):
+ '''Return providers of this related package. Does *not* include exact
+ matches as it checks the Provision names only, use get_best_satisfier()
+ instead for exact matches.'''
+ pkgs = Package.objects.normal().filter(
+ provides__name=self.name).order_by().distinct()
+ if not self.pkg.arch.agnostic:
+ # make sure we match architectures if possible
+ arches = self.pkg.applicable_arches()
+ pkgs = pkgs.filter(arch__in=arches)
+
+ # Logic here is to filter out packages that are in multiple repos if
+ # they are not requested. For example, if testing is False, only show a
+ # testing package if it doesn't exist in a non-testing repo.
+ filtered = {}
+ for package in pkgs:
+ if package.pkgname not in filtered or \
+ package.repo.staging == self.pkg.repo.staging:
+ filtered[package.pkgname] = package
+ pkgs = filtered.values()
+
+ filtered = {}
+ for package in pkgs:
+ if package.pkgname not in filtered or \
+ package.repo.testing == self.pkg.repo.testing:
+ filtered[package.pkgname] = package
+ pkgs = filtered.values()
+
+ return pkgs
+
def __unicode__(self):
if self.version:
return u'%s%s%s' % (self.name, self.comparison, self.version)
diff --git a/packages/utils.py b/packages/utils.py
index 8d00bd6..8231347 100644
--- a/packages/utils.py
+++ b/packages/utils.py
@@ -7,10 +7,10 @@ from django.db import connection
from django.db.models import Count, Max, F
from django.contrib.auth.models import User
-from main.models import Package, PackageDepend, PackageFile, Arch, Repo
+from main.models import Package, PackageFile, Arch, Repo
from main.utils import cache_function, groupby_preserve_order, PackageStandin
from .models import (PackageGroup, PackageRelation,
- License, Conflict, Provision, Replacement,
+ License, Depend, Conflict, Provision, Replacement,
SignoffSpecification, Signoff, DEFAULT_SIGNOFF_SPEC)
@cache_function(127)
@@ -451,7 +451,7 @@ class PackageJSONEncoder(DjangoJSONEncoder):
return obj.name.lower()
if isinstance(obj, (PackageGroup, License)):
return obj.name
- if isinstance(obj, (Conflict, Provision, Replacement, PackageDepend)):
+ if isinstance(obj, (Depend, Conflict, Provision, Replacement)):
return unicode(obj)
elif isinstance(obj, User):
return obj.username