--- /dev/null
+###############################################################################
+# #
+# Pakfire - The IPFire package management system #
+# Copyright (C) 2025 Pakfire development team #
+# #
+# This program is free software: you can redistribute it and/or modify #
+# it under the terms of the GNU General Public License as published by #
+# the Free Software Foundation, either version 3 of the License, or #
+# (at your option) any later version. #
+# #
+# This program is distributed in the hope that it will be useful, #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
+# GNU General Public License for more details. #
+# #
+# You should have received a copy of the GNU General Public License #
+# along with this program. If not, see <http://www.gnu.org/licenses/>. #
+# #
+###############################################################################
+
+import fastapi
+import pydantic
+
+from . import apiv1
+from . import backend
+
+# Create a new router for all endpoints
+router = fastapi.APIRouter(
+ prefix="/packages",
+ tags=["Packages"],
+)
+
+class PackageSummary(pydantic.BaseModel):
+ """
+ This is a helper model to shorten the list of packages which
+ would otherwise generate an API response that is just under
+ half a megabyte.
+ """
+ # Name
+ name: str
+
+ # Summary
+ summary: str
+
+
+@router.get("")
+async def get_packages() -> list[PackageSummary]:
+ """
+ An endpoint to list all available packages
+ """
+ return [package async for package in backend.packages]
+
+# Add everything to the APIv1
+apiv1.include_router(router)
log = logging.getLogger("pbs.packages")
class Packages(base.Object):
- async def list(self):
+ def __aiter__(self):
"""
Returns a list with all package names and the summary line
that have at one time been part of the distribution
"""
- stmt = \
- sqlalchemy.select(
+ stmt = (
+ sqlmodel
+ .select(
+ Package,
+ )
+ .distinct(
Package.name,
- Package.summary,
- Package.created_at,
- ) \
- .distinct(Package.name) \
- .select_from(Package) \
+ )
.join(
builds.Build,
Package.id == builds.Build.pkg_id,
isouter=True,
- ) \
+ )
.where(
Package.deleted_at == None,
builds.Build.deleted_at == None,
Package.arch == "src",
- ) \
+ )
.order_by(
Package.name,
Package.created_at.desc(),
)
+ )
- return self.db.select(stmt)
+ return self.db.fetch(stmt)
async def get_by_uuid(self, uuid):
stmt = (