Verified Commit be7a9607 authored by Kevin Morris's avatar Kevin Morris
Browse files

fix: handle broken packages which have valid provides

Closes #226



Signed-off-by: Kevin Morris's avatarKevin Morris <kevr@0cost.org>
parent 6fdaeee0
Pipeline #14192 passed with stages
in 7 minutes and 50 seconds
from typing import List
from sqlalchemy import and_, literal
from sqlalchemy.exc import IntegrityError
from sqlalchemy.orm import backref, relationship
......@@ -6,6 +9,7 @@ from aurweb.models.declarative import Base
from aurweb.models.dependency_type import DependencyType as _DependencyType
from aurweb.models.official_provider import OfficialProvider as _OfficialProvider
from aurweb.models.package import Package as _Package
from aurweb.models.package_relation import PackageRelation
class PackageDependency(Base):
......@@ -51,3 +55,24 @@ class PackageDependency(Base):
official = db.query(_OfficialProvider).filter(
_OfficialProvider.Name == self.DepName).exists()
return db.query(pkg).scalar() or db.query(official).scalar()
def provides(self) -> List[PackageRelation]:
from aurweb.models.relation_type import PROVIDES_ID
rels = db.query(PackageRelation).join(_Package).filter(
and_(PackageRelation.RelTypeID == PROVIDES_ID,
PackageRelation.RelName == self.DepName)
).with_entities(
_Package.Name,
literal(False).label("is_official")
).order_by(_Package.Name.asc())
official_rels = db.query(_OfficialProvider).filter(
and_(_OfficialProvider.Provides == self.DepName,
_OfficialProvider.Name != self.DepName)
).with_entities(
_OfficialProvider.Name,
literal(True).label("is_official")
).order_by(_OfficialProvider.Name.asc())
return rels.union(official_rels).all()
......@@ -5,18 +5,20 @@ from typing import Dict, List, Union
import orjson
from fastapi import HTTPException, Request
from sqlalchemy import and_, orm
from sqlalchemy import orm
from aurweb import db, l10n, models, util
from aurweb.models import Package, PackageBase, User
from aurweb.models.official_provider import OFFICIAL_BASE, OfficialProvider
from aurweb.models.package_comaintainer import PackageComaintainer
from aurweb.models.package_dependency import PackageDependency
from aurweb.models.relation_type import PROVIDES_ID
from aurweb.models.package_relation import PackageRelation
from aurweb.redis import redis_connection
from aurweb.scripts import notify
from aurweb.templates import register_filter
Providers = List[Union[PackageRelation, OfficialProvider]]
def dep_extra_with_arch(dep: models.PackageDependency, annotation: str) -> str:
output = [annotation]
......@@ -77,27 +79,13 @@ def package_link(package: Union[Package, OfficialProvider]) -> str:
return f"/packages/{package.Name}"
@register_filter("provides_list")
def provides_list(package: models.Package, depname: str) -> list:
providers = db.query(models.Package).join(
models.PackageRelation).join(models.RelationType).filter(
and_(
models.PackageRelation.RelName == depname,
models.RelationType.ID == PROVIDES_ID
)
)
string = ", ".join([
@register_filter("provides_markup")
def provides_markup(provides: Providers) -> str:
return ", ".join([
f'<a href="{package_link(pkg)}">{pkg.Name}</a>'
for pkg in providers
for pkg in provides
])
if string:
# If we actually constructed a string, wrap it.
string = f"<em>({string})</em>"
return string
def get_pkg_or_base(
name: str,
......
<div id="pkgdeps" class="listing">
<h3>Dependencies ({{ dependencies | length }})</h3>
<h3>{{ "Dependencies" | tr }} ({{ dependencies | length }})</h3>
<ul id="pkgdepslist">
{% for dep in dependencies %}
{# Collect provides for `dep`. #}
{% set provides = dep.provides() %}
<li>
{% set broken = not dep.is_package() %}
{% if broken %}
<span class="broken">
{% if not provides %}
<span class="broken">
{% endif %}
{% else %}
<a href="{{ dep.DepName | pkgname_link }}">
{% endif %}
{{ dep.DepName }}
{% if broken %}
</span>
{% if not provides %}
</span>
{% endif %}
{% else %}
</a>
{% endif %}
{{ dep.Package | provides_list(dep.DepName) | safe }}
{# If this dependency type is an optdepends (id: 4). #}
{% if provides %}
<em>({{ provides | provides_markup | safe }})</em>
{% endif %}
{% if dep.DepTypeID == 4 %}
{# If this dependency type is an optdepends (id: 4). #}
<em>{{ dep | dep_extra_desc }}</em>
{% else %}
<em>{{ dep | dep_extra }}</em>
......@@ -28,7 +38,7 @@
</div>
<div id="pkgreqs" class="listing">
<h3>Required by ({{ required_by | length }})</h3>
<h3>{{ "Required by" | tr }} ({{ required_by | length }})</h3>
<ul id="pkgreqslist">
{% for dep in required_by %}
<li>
......@@ -49,7 +59,7 @@
</div>
<div id="pkgfiles" class="listing">
<h3>Sources ({{ sources | length }})</h3>
<h3>{{ "Sources" | tr }} ({{ sources | length }})</h3>
</div>
<div>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment