From 5ae11b5e2c8238d6aebd603e9a3931f472573674 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Tue, 11 Feb 2025 13:59:32 +0000 Subject: [PATCH] releases: Add a simple listing of images Signed-off-by: Michael Tremer --- Makefile.am | 5 +++ src/buildservice/images.py | 17 +++++++ src/templates/distros/releases/show.html | 8 ++++ src/templates/images/macros.html | 57 ++++++++++++++++++++++++ 4 files changed, 87 insertions(+) create mode 100644 src/templates/images/macros.html diff --git a/Makefile.am b/Makefile.am index 3d9d3b63..6794c73f 100644 --- a/Makefile.am +++ b/Makefile.am @@ -243,6 +243,11 @@ dist_templates_events_DATA = \ templates_eventsdir = $(templatesdir)/events +dist_templates_images_DATA = \ + src/templates/images/macros.html + +templates_imagesdir = $(templatesdir)/images + dist_templates_jobs_DATA = \ src/templates/jobs/abort.html \ src/templates/jobs/index.html \ diff --git a/src/buildservice/images.py b/src/buildservice/images.py index e3c832ed..6833dea0 100644 --- a/src/buildservice/images.py +++ b/src/buildservice/images.py @@ -32,6 +32,14 @@ log = logging.getLogger("pbs.images") class Image(database.Base, database.BackendMixin, database.SoftDeleteMixin): __tablename__ = "images" + # Sorting + + def __lt__(self, other): + if isinstance(other, self.__class__): + return self.arch < other.arch + + return NotImplemented + # ID id = Column(Integer, primary_key=True) @@ -82,6 +90,15 @@ class Image(database.Base, database.BackendMixin, database.SoftDeleteMixin): path = Column(Text, nullable=False) + # Link + + @property + def link(self): + """ + Returns a link where clients can download this image from + """ + return self.backend.path_to_url(self.path, mirrored=self.release.is_mirrored()) + # Size size = Column(BigInteger, nullable=False) diff --git a/src/templates/distros/releases/show.html b/src/templates/distros/releases/show.html index 3730874b..952c702e 100644 --- a/src/templates/distros/releases/show.html +++ b/src/templates/distros/releases/show.html @@ -1,6 +1,7 @@ {% extends "base.html" %} {% from "macros.html" import Text with context %} +{% from "images/macros.html" import ImageList with context %} {% block title %}{{ distro }} - {{ release }}{% endblock %} @@ -81,4 +82,11 @@ {% endif %} + + {# Images #} +
+
+ {{ ImageList(release.images) }} +
+
{% endblock %} diff --git a/src/templates/images/macros.html b/src/templates/images/macros.html new file mode 100644 index 00000000..14bfe5c1 --- /dev/null +++ b/src/templates/images/macros.html @@ -0,0 +1,57 @@ +{% macro ImageList(images) %} + {% for type, images in images | groupby("type") %} +
+ {# Headline #} +
+ {% if type == "iso" %} + {{ _("ISO Image") }} + {% elif type == "oci" %} + {{ _("Container Image") }} + {% else %} + + {{ _("Unknown Image Type") }} + + {% endif %} +
+ +
+
+ {% for image in images | sort %} +
+ +
+ {% endfor %} +
+
+
+ {% endfor %} +{% endmacro %} -- 2.47.2