diff options
author | Dan McGee <dan@archlinux.org> | 2010-03-06 16:03:41 -0600 |
---|---|---|
committer | Dan McGee <dan@archlinux.org> | 2010-03-06 16:03:41 -0600 |
commit | 9374a2821c3c3d5be4f2b32bc404b920698d5281 (patch) | |
tree | fe731a1688c91232523eb01d527074b7e47dc61d | |
parent | d4155f7d0fcec64f45f713e5bfdd33db990023b0 (diff) |
Fix up get_depends logic a bit
We were not handing depends of 'any' packages correctly if they depended on
arch-dependent packages; we labeled them all as virtual. If we have an 'any'
package, drop the arch screening and just pick one to link to.
Signed-off-by: Dan McGee <dan@archlinux.org>
-rw-r--r-- | main/models.py | 28 |
1 files changed, 16 insertions, 12 deletions
diff --git a/main/models.py b/main/models.py index a022b8eb..fabb8673 100644 --- a/main/models.py +++ b/main/models.py @@ -222,7 +222,7 @@ class Package(models.Model): """ requiredby = Package.objects.select_related('arch', 'repo').filter( packagedepend__depname=self.pkgname, - arch__name__in=(self.arch.name, 'Any')) + arch__name__in=(self.arch.name, 'any')) return requiredby.order_by('pkgname') def get_depends(self): @@ -238,23 +238,27 @@ class Package(models.Model): deps = [] # TODO: we can use list comprehension and an 'in' query to make this more effective for dep in self.packagedepend_set.order_by('depname'): - # we only need depend on same-arch-packages - pkgs = Package.objects.select_related('arch', 'repo').filter( - Q(arch__name__iexact='any') | Q(arch=self.arch), - pkgname=dep.depname) + pkgs = Package.objects.select_related('arch', 'repo').filter(pkgname=dep.depname) + if self.arch.name != 'any': + # make sure we match architectures if possible + pkgs = pkgs.filter(arch__name__in=(self.arch.name, 'any')) if len(pkgs) == 0: # couldn't find a package in the DB # it should be a virtual depend (or a removed package) - deps.append({'dep': dep, 'pkg': None}) + pkg = None elif len(pkgs) == 1: - deps.append({'dep': dep, 'pkg': pkgs[0]}) + pkg = pkgs[0] else: - tpkgs = pkgs.filter(repo__testing=True) - if len(tpkgs) == 1: - deps.append({'dep': dep, 'pkg': tpkgs[0]}) + # more than one package, see if we can't shrink it down + # grab the first though in case we fail + pkg = pkgs[0] + if self.repo.testing: + pkgs = pkgs.filter(repo__testing=True) else: - for pkg in pkgs: - deps.append({'dep': dep, 'pkg': pkg}) + pkgs = pkgs.filter(repo__testing=False) + if len(pkgs) > 0: + pkg = pkgs[0] + deps.append({'dep': dep, 'pkg': pkg}) self.deps_cache = deps return deps |