summaryrefslogtreecommitdiffstats
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
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>
-rw-r--r--devel/management/commands/reporead.py18
-rw-r--r--devel/views.py6
-rw-r--r--main/models.py7
-rw-r--r--packages/models.py34
-rw-r--r--packages/utils.py6
-rw-r--r--templates/packages/details_depend.html6
-rw-r--r--templates/packages/details_requiredby.html2
7 files changed, 54 insertions, 25 deletions
diff --git a/devel/management/commands/reporead.py b/devel/management/commands/reporead.py
index fd8e397..47294d9 100644
--- a/devel/management/commands/reporead.py
+++ b/devel/management/commands/reporead.py
@@ -29,9 +29,9 @@ from django.db import connections, router, transaction
from django.db.utils import IntegrityError
from devel.utils import UserFinder
-from main.models import Arch, Package, PackageDepend, PackageFile, Repo
+from main.models import Arch, Package, PackageFile, Repo
from main.utils import utc_now
-from packages.models import Conflict, Provision, Replacement
+from packages.models import Depend, Conflict, Provision, Replacement
logging.basicConfig(
@@ -141,19 +141,21 @@ class RepoPackage(object):
return u'%s-%s' % (self.ver, self.rel)
-DEPEND_RE = re.compile(r"^(.+?)((>=|<=|=|>|<)(.*))?$")
+DEPEND_RE = re.compile(r"^(.+?)((>=|<=|=|>|<)(.+))?$")
def create_depend(package, dep_str, optional=False):
- depend = PackageDepend(pkg=package, optional=optional)
+ depend = Depend(pkg=package, optional=optional)
# lop off any description first
parts = dep_str.split(':', 1)
if len(parts) > 1:
depend.description = parts[1].strip()
match = DEPEND_RE.match(parts[0].strip())
if match:
- depend.depname = match.group(1)
- if match.group(2):
- depend.depvcmp = match.group(2)
+ depend.name = match.group(1)
+ if match.group(3):
+ depend.comparison = match.group(3)
+ if match.group(4):
+ related.version = match.group(4)
else:
logger.warning('Package %s had unparsable depend string %s',
package.pkgname, dep_str)
@@ -232,7 +234,7 @@ def populate_pkg(dbpkg, repopkg, force=False, timestamp=None):
dbpkg.depends.all().delete()
deps = [create_depend(dbpkg, y) for y in repopkg.depends]
deps += [create_depend(dbpkg, y, True) for y in repopkg.optdepends]
- PackageDepend.objects.bulk_create(deps)
+ Depend.objects.bulk_create(deps)
dbpkg.conflicts.all().delete()
conflicts = [create_related(Conflict, dbpkg, y) for y in repopkg.conflicts]
diff --git a/devel/views.py b/devel/views.py
index 0f1c8d1..16b6acc 100644
--- a/devel/views.py
+++ b/devel/views.py
@@ -26,11 +26,11 @@ from django.utils.encoding import force_unicode
from django.utils.http import http_date
from .models import UserProfile
-from main.models import Package, PackageDepend, PackageFile, TodolistPkg
+from main.models import Package, PackageFile, TodolistPkg
from main.models import Arch, Repo
from main.utils import utc_now
from news.models import News
-from packages.models import PackageRelation, Signoff
+from packages.models import PackageRelation, Signoff, Depend
from packages.utils import get_signoff_groups
from todolists.utils import get_annotated_todolists
from .utils import get_annotated_maintainers, UserFinder
@@ -267,7 +267,7 @@ def report(request, report_name, username=None):
elif report_name == 'unneeded-orphans':
title = 'Orphan packages required by no other packages'
owned = PackageRelation.objects.all().values('pkgbase')
- required = PackageDepend.objects.all().values('depname')
+ required = Depend.objects.all().values('name')
# The two separate calls to exclude is required to do the right thing
packages = packages.exclude(pkgbase__in=owned).exclude(
pkgname__in=required)
diff --git a/main/models.py b/main/models.py
index 4b445dd..f17d4a4 100644
--- a/main/models.py
+++ b/main/models.py
@@ -180,11 +180,12 @@ class Package(models.Model):
list slim by including the corresponding package in the same testing
category as this package if that check makes sense.
"""
+ from packages.models import Depend
provides = set(self.provides.values_list('name', flat=True))
provides.add(self.pkgname)
- requiredby = PackageDepend.objects.select_related('pkg',
+ requiredby = Depend.objects.select_related('pkg',
'pkg__arch', 'pkg__repo').filter(
- depname__in=provides).order_by(
+ name__in=provides).order_by(
'pkg__pkgname', 'pkg__arch__name', 'pkg__repo__name')
if not self.arch.agnostic:
# make sure we match architectures if possible
@@ -232,7 +233,7 @@ class Package(models.Model):
deps = []
arches = None
# TODO: we can use list comprehension and an 'in' query to make this more effective
- for dep in self.depends.order_by('optional', 'depname'):
+ for dep in self.depends.order_by('optional', 'name'):
pkg = dep.get_best_satisfier()
providers = None
if not pkg:
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
diff --git a/templates/packages/details_depend.html b/templates/packages/details_depend.html
index 8b6e85c..0cf2c36 100644
--- a/templates/packages/details_depend.html
+++ b/templates/packages/details_depend.html
@@ -2,12 +2,12 @@
<li>
{% ifequal depend.pkg None %}
{% if depend.providers %}
-{{ depend.dep.depname }} <span class="virtual-dep">({% multi_pkg_details depend.providers %})</span>
+{{ depend.dep.name }}{{ depend.dep.comparison|default:"" }}{{ depend.dep.version|default:"" }} <span class="virtual-dep">({% multi_pkg_details depend.providers %})</span>
{% else %}
-{{ depend.dep.depname }} <span class="virtual-dep">(virtual)</span>
+{{ depend.dep.name }}{{ depend.dep.comparison|default:"" }}{{ depend.dep.version|default:"" }} <span class="virtual-dep">(virtual)</span>
{% endif %}
{% else %}
-{% pkg_details_link depend.pkg %}{{ depend.dep.depvcmp|default:"" }}
+{% pkg_details_link depend.pkg %}{{ depend.dep.comparison|default:"" }}{{ depend.dep.version|default:"" }}
{% if depend.pkg.repo.testing %} <span class="testing-dep">(testing)</span>{% endif %}
{% if depend.pkg.repo.staging %} <span class="staging-dep">(staging)</span>{% endif %}
{% endifequal %}
diff --git a/templates/packages/details_requiredby.html b/templates/packages/details_requiredby.html
index c769728..ecc92b2 100644
--- a/templates/packages/details_requiredby.html
+++ b/templates/packages/details_requiredby.html
@@ -1,6 +1,6 @@
{% load package_extras %}
<li>{% pkg_details_link req.pkg %}
-{% if req.depname != pkg.pkgname %}<span class="virtual-dep">(requires {{ req.depname }})</span>{% endif %}
+{% if req.name != pkg.pkgname %}<span class="virtual-dep">(requires {{ req.name }})</span>{% endif %}
{% if req.pkg.repo.testing %}<span class="testing-dep">(testing)</span>{% endif %}
{% if req.pkg.repo.staging %}<span class="staging-dep">(staging)</span>{% endif %}
{% if req.optional %}<span class="opt-dep">(optional)</span>{% endif %}