diff options
author | Dan McGee <dan@archlinux.org> | 2010-12-07 13:31:59 -0600 |
---|---|---|
committer | Dan McGee <dan@archlinux.org> | 2010-12-07 13:31:59 -0600 |
commit | 681dba9eef7991c5113d35562b3ace55bb782ad4 (patch) | |
tree | 8e6f841b35ea54b382d36cf554f9bc2bee19c46d /main/models.py | |
parent | 9ea7fb8955c2d5887b8c00a1002316c25350e9c1 (diff) |
Move some common package code to a function
We do this determination of 'applicable arches' a few times, so move it to a
method on the package object and also clean things up so items aren't
duplicated in the list.
Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'main/models.py')
-rw-r--r-- | main/models.py | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/main/models.py b/main/models.py index 51cf89a8..af4466ff 100644 --- a/main/models.py +++ b/main/models.py @@ -157,15 +157,20 @@ class Package(models.Model): return len(self.signoffs) >= 2 @cache_function(300) + def applicable_arches(self): + '''The list of (this arch) + (available agnostic arches).''' + arches = set(Arch.objects.filter(agnostic=True)) + arches.add(self.arch) + return list(arches) + + @cache_function(300) def get_requiredby(self): """ 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__in=arches).distinct() + arch__in=self.applicable_arches()).distinct() return requiredby.order_by('pkgname') @cache_function(300) @@ -176,15 +181,13 @@ 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 not self.arch.agnostic: # make sure we match architectures if possible - pkgs = pkgs.filter(arch__in=arches) + pkgs = pkgs.filter(arch__in=self.applicable_arches()) if len(pkgs) == 0: # couldn't find a package in the DB # it should be a virtual depend (or a removed package) @@ -231,7 +234,7 @@ class Package(models.Model): repo.testing flag. For any non-split packages, the return value will be an empty list. """ - return Package.objects.filter(arch=self.arch, + return Package.objects.filter(arch__in=self.applicable_arches, repo__testing=self.repo.testing, pkgbase=self.pkgbase).exclude(id=self.id) def get_svn_link(self, svnpath): |