Source code for dakweb.routers.madison

# SPDX-License-Identifier:  GPL-2.0-or-later
# © 2026, Anton Gladky <gladk@debian.org>

from typing import Annotated

from fastapi import APIRouter, Query
from starlette.responses import JSONResponse, StreamingResponse

from daklib.ls import list_packages

router = APIRouter()


[docs] @router.get("/madison") def madison( package: Annotated[ str, Query(description="Space separated list of packages.") ] = "", a: Annotated[ str | None, Query(description="Comma separated list of architectures.") ] = None, b: Annotated[str | None, Query(description="Binary type (deb/udeb/dsc).")] = None, c: Annotated[ str | None, Query(description="Comma separated list of components.") ] = None, s: Annotated[ str | None, Query(description="Comma separated list of suites.") ] = None, S: Annotated[ str | None, Query( alias="S", description="If present, include binary children of source pkgs.", ), ] = None, f: Annotated[str | None, Query(description="If present, output JSON.")] = None, ): """Display information about package(s) ("madison" interface).""" packages = package.split() architectures = a.split(",") if a is not None else None binary_types = [b] if b is not None else None components = c.split(",") if c is not None else None suites = s.split(",") if s is not None else None source_and_binary = S is not None # Bottle used presence of 'f' to indicate JSON output, regardless of value. output_format = "python" if f is not None else None result = list_packages( packages, suites=suites, components=components, architectures=architectures, binary_types=binary_types, source_and_binary=source_and_binary, format=output_format, ) if f is None: def gen(): for row in result: yield f"{row}\n" return StreamingResponse(gen(), media_type="text/plain; charset=UTF-8") return JSONResponse( content=list(result), media_type="application/json; charset=UTF-8" )