diff options
author | Dan McGee <dan@archlinux.org> | 2012-08-07 19:36:07 -0500 |
---|---|---|
committer | Dan McGee <dan@archlinux.org> | 2012-08-07 19:36:07 -0500 |
commit | f63a70f5118781fe34d82ae0d59c911f0ea28d1d (patch) | |
tree | d9e4f1affa488f6a60b7d2e7434d9370ec2171cb /packages | |
parent | 2cb15547b0d3dfee46f3d51341bebd0b1251c0f9 (diff) |
Make use of new ctypes ALPM API
We can use this when filtering down lists of depends, required by,
conflicts, etc. to ensure we are honoring the version specifications the
same way pacman would.
Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'packages')
-rw-r--r-- | packages/models.py | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/packages/models.py b/packages/models.py index 1959183f..403dfef0 100644 --- a/packages/models.py +++ b/packages/models.py @@ -7,6 +7,7 @@ from django.contrib.auth.models import User from main.models import Arch, Repo, Package from main.utils import set_created_field, database_vendor +from packages.alpm import AlpmAPI class PackageRelation(models.Model): @@ -341,6 +342,13 @@ class RelatedToBase(models.Model): # make sure we match architectures if possible arches = self.pkg.applicable_arches() pkgs = pkgs.filter(arch__in=arches) + # if we have a comparison operation, make sure the packages we grab + # actually satisfy the requirements + if self.comparison and self.version: + alpm = AlpmAPI() + pkgs = [pkg for pkg in pkgs if not alpm.available or + alpm.compare_versions(pkg.full_version, self.comparison, + self.version)] if len(pkgs) == 0: # couldn't find a package in the DB # it should be a virtual depend (or a removed package) @@ -373,6 +381,21 @@ class RelatedToBase(models.Model): arches = self.pkg.applicable_arches() pkgs = pkgs.filter(arch__in=arches) + # If we have a comparison operation, make sure the packages we grab + # actually satisfy the requirements. + alpm = AlpmAPI() + if alpm.available and self.comparison and self.version: + pkgs = pkgs.prefetch_related('provides') + new_pkgs = [] + for package in pkgs: + for provide in package.provides.all(): + if provide.name != self.name: + continue + if alpm.compare_versions(provide.version, + self.comparison, self.version): + new_pkgs.append(package) + pkgs = new_pkgs + # 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. |