From 04da5f03b254a6000c92eb4e32bdfaa88724f4a4 Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Wed, 8 Sep 2010 11:12:43 -0500 Subject: Use arch.agnostic flag everywhere Signed-off-by: Dan McGee --- feeds.py | 4 ++-- main/models.py | 13 +++++++++---- packages/views.py | 10 ++++++---- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/feeds.py b/feeds.py index b149c4a..c6395f8 100644 --- a/feeds.py +++ b/feeds.py @@ -18,7 +18,7 @@ class PackageFeed(Feed): if arch != '': # feed for a single arch, also include 'any' packages everywhere a = Arch.objects.get(name=arch) - qs = qs.filter(Q(arch=a) | Q(arch__name='any')) + qs = qs.filter(Q(arch=a) | Q(arch__agnostic=True)) obj['arch'] = a if repo != '': # feed for a single arch AND repo @@ -40,7 +40,7 @@ class PackageFeed(Feed): s = 'Recently updated packages in the Arch Linux package repositories' if 'arch' in obj: s += ' for the \'%s\' architecture' % obj['arch'].name.lower() - if obj['arch'].name != 'any': + if not obj['arch'].agnostic: s += ' (including \'any\' packages)' if 'repo' in obj: s += ' in the [%s] repository' % obj['repo'].name.lower() diff --git a/main/models.py b/main/models.py index 70ab4bd..0f4ae96 100644 --- a/main/models.py +++ b/main/models.py @@ -155,9 +155,11 @@ class Package(models.Model): """ Returns a list of package objects. """ + arches = list(Arch.objects.filter(agnostic=True)) + arches.append(self.arch) requiredby = Package.objects.select_related('arch', 'repo').filter( packagedepend__depname=self.pkgname, - arch__name__in=(self.arch.name, 'any')).distinct() + arch__in=arches).distinct() return requiredby.order_by('pkgname') @cache_function(300) @@ -168,12 +170,15 @@ class Package(models.Model): else pkg will be None if it is a 'virtual' dependency. """ deps = [] + arches = list(Arch.objects.filter(agnostic=True)) + arches.append(self.arch) # TODO: we can use list comprehension and an 'in' query to make this more effective for dep in self.packagedepend_set.order_by('depname'): - pkgs = Package.objects.select_related('arch', 'repo').filter(pkgname=dep.depname) - if self.arch.name != 'any': + pkgs = Package.objects.select_related('arch', 'repo').filter( + pkgname=dep.depname) + if not self.arch.agnostic: # make sure we match architectures if possible - pkgs = pkgs.filter(arch__name__in=(self.arch.name, 'any')) + pkgs = pkgs.filter(arch__in=arches) if len(pkgs) == 0: # couldn't find a package in the DB # it should be a virtual depend (or a removed package) diff --git a/packages/views.py b/packages/views.py index 784d254..4cc4cc2 100644 --- a/packages/views.py +++ b/packages/views.py @@ -87,8 +87,10 @@ def groups(request): def group_details(request, arch, name): arch = get_object_or_404(Arch, name=arch) - pkgs = Package.objects.filter(packagegroup__name=name) - pkgs = pkgs.filter(Q(arch__name=arch) | Q(arch__name='any')) + arches = [ arch ] + arches.extend(Arch.objects.filter(agnostic=True)) + pkgs = Package.objects.filter(packagegroup__name=name, + arch__in=arches) pkgs = pkgs.order_by('pkgname') if len(pkgs) == 0: raise Http404 @@ -350,9 +352,9 @@ def download(request, name='', repo='', arch=''): mirror__public=True, mirror__active=True, protocol__protocol__iexact='HTTP')[0] arch = pkg.arch.name - if arch == 'any': + if pkg.arch.agnostic: # grab the first non-any arch to fake the download path - arch = Arch.objects.exclude(name='any')[0].name + arch = Arch.objects.exclude(agnostic=True)[0].name details = { 'host': mirrorurl.url, 'arch': arch, -- cgit v1.2.3-24-g4f1b