mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
fix(routers.packages): handle package source display
Signed-off-by: Kevin Morris <kevr@0cost.org>
This commit is contained in:
parent
be7a96076e
commit
8f8929f324
3 changed files with 66 additions and 4 deletions
|
@ -1,13 +1,13 @@
|
|||
from collections import defaultdict
|
||||
from http import HTTPStatus
|
||||
from typing import Dict, List, Union
|
||||
from typing import Dict, List, Tuple, Union
|
||||
|
||||
import orjson
|
||||
|
||||
from fastapi import HTTPException, Request
|
||||
from sqlalchemy import orm
|
||||
|
||||
from aurweb import db, l10n, models, util
|
||||
from aurweb import config, 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
|
||||
|
@ -382,3 +382,30 @@ def pkg_required(pkgname: str, provides: List[str], limit: int) \
|
|||
PackageDependency.DepName.in_(targets)
|
||||
).order_by(Package.Name.asc()).limit(limit)
|
||||
return query.all()
|
||||
|
||||
|
||||
@register_filter("source_uri")
|
||||
def source_uri(pkgsrc: models.PackageSource) -> Tuple[str, str]:
|
||||
"""
|
||||
Produce a (text, uri) tuple out of `pkgsrc`.
|
||||
|
||||
In this filter, we cover various cases:
|
||||
1. If "::" is anywhere in the Source column, split the string,
|
||||
which should produce a (text, uri), where text is before "::"
|
||||
and uri is after "::".
|
||||
2. Otherwise, if "://" is anywhere in the Source column, it's just
|
||||
some sort of URI, which we'll return varbatim as both text and uri.
|
||||
3. Otherwise, we'll return a path to the source file in a uri produced
|
||||
out of options.source_file_uri formatted with the source file and
|
||||
the package base name.
|
||||
|
||||
:param pkgsrc: PackageSource instance
|
||||
:return (text, uri) tuple
|
||||
"""
|
||||
if "::" in pkgsrc.Source:
|
||||
return pkgsrc.Source.split("::", 1)
|
||||
elif "://" in pkgsrc.Source:
|
||||
return (pkgsrc.Source, pkgsrc.Source)
|
||||
path = config.get("options", "source_file_uri")
|
||||
pkgbasename = pkgsrc.Package.PackageBase.Name
|
||||
return (pkgsrc.Source, path % (pkgsrc.Source, pkgbasename))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue