From: Michael Tremer Date: Tue, 23 May 2023 13:06:27 +0000 (+0000) Subject: monitorings: Create some first pages to show current status X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=594b420f14e6eb9d618be81bf722806b0be9adee;p=pbs.git monitorings: Create some first pages to show current status Signed-off-by: Michael Tremer --- diff --git a/Makefile.am b/Makefile.am index 0fb7ec55..3ccfb95d 100644 --- a/Makefile.am +++ b/Makefile.am @@ -135,6 +135,7 @@ web_PYTHON = \ src/web/jobs.py \ src/web/keys.py \ src/web/mirrors.py \ + src/web/monitorings.py \ src/web/packages.py \ src/web/repos.py \ src/web/search.py \ @@ -231,6 +232,16 @@ dist_templates_distros_modules_DATA = \ templates_distros_modulesdir = $(templates_distrosdir)/modules +dist_templates_monitorings_DATA = \ + src/templates/monitorings/show.html + +templates_monitoringsdir = $(templatesdir)/monitorings + +dist_templates_monitorings_modules_DATA = \ + src/templates/monitorings/modules/releases-list.html + +templates_monitorings_modulesdir = $(templates_monitoringsdir)/modules + dist_templates_errors_DATA = \ src/templates/errors/error.html diff --git a/src/buildservice/releasemonitoring.py b/src/buildservice/releasemonitoring.py index 1f790ff1..1144434a 100644 --- a/src/buildservice/releasemonitoring.py +++ b/src/buildservice/releasemonitoring.py @@ -123,6 +123,21 @@ class Monitorings(base.Object): """, id, ) + def get_by_distro_and_name(self, distro, name): + return self._get_monitoring(""" + SELECT + * + FROM + release_monitorings + WHERE + deleted_at IS NULL + AND + distro_id = %s + AND + name = %s + """, distro, name, + ) + async def create(self, distro, name, created_by, project_id, follow="mainline", create_builds=True): monitoring = self._get_monitoring(""" @@ -202,6 +217,10 @@ class Monitoring(base.DataObject): return "%s - %s" % (self.distro, self.name) @property + def url(self): + return "/distros/%s/monitorings/%s" % (self.distro.slug, self.name) + + @lazy_property def distro(self): """ The distribution @@ -219,6 +238,12 @@ class Monitoring(base.DataObject): def project_id(self): return self.data.project_id + # Last Check At + + @property + def last_check_at(self): + return self.data.last_check_at + @property def follow(self): return self.data.follow @@ -289,8 +314,6 @@ class Monitoring(base.DataObject): FROM release_monitoring_releases WHERE - deleted_at IS NULL - AND monitoring_id = %s ORDER BY created_at DESC @@ -405,6 +428,12 @@ class Release(base.DataObject): def version(self): return self.data.version + # Created At + + @property + def created_at(self): + return self.data.created_at + # Bug async def _create_bug(self): @@ -453,6 +482,10 @@ class Release(base.DataObject): return bug + @property + def bug_id(self): + return self.data.bug_id + # Build def get_build(self): diff --git a/src/templates/monitorings/modules/releases-list.html b/src/templates/monitorings/modules/releases-list.html new file mode 100644 index 00000000..a18f69fb --- /dev/null +++ b/src/templates/monitorings/modules/releases-list.html @@ -0,0 +1,25 @@ +{# Show a message if we don't have any releases, yet #} +{% if show_empty and not releases %} +

+ {{ _("No new releases have been found, yet") }} +

+ +{# Show releases #} +{% elif releases %} + {% for release in releases %} +
+
+
+ {{ release }} + + + {{ _("Bug #%s") % release.bug_id }} + +
+
{{ locale.format_date(release.created_at, shorter=True) }}
+ + {# XXX Show build and build status #} +
+
+ {% end %} +{% end %} diff --git a/src/templates/monitorings/show.html b/src/templates/monitorings/show.html new file mode 100644 index 00000000..f44f152b --- /dev/null +++ b/src/templates/monitorings/show.html @@ -0,0 +1,93 @@ +{% extends "../base.html" %} + +{% block title %}{{ _("Release Monitoring") }} - {{ monitoring }}{% end block %} + +{% block body %} +
+
+
+ + +

{{ monitoring }}

+ +
+ {% if monitoring.latest_release %} +
+
+

{{ _("Latest Release") }}

+

+ {{ monitoring.latest_release.version }} +

+
+
+ {% end %} + + {% if monitoring.latest_build %} +
+
+

{{ _("Current Release") }}

+

+ + {{ monitoring.latest_build.pkg.evr }} + +

+
+
+ {% end %} + +
+
+

{{ _("Last Check") }}

+

+ {{ locale.format_date(monitoring.last_check_at, shorter=True) }} +

+
+
+
+
+
+
+ + {% if current_user and current_user.is_admin() %} +
+ +
+ {% end %} + + {# List Releases #} +
+
+ {% module MonitoringsReleasesList(monitoring.releases) %} +
+
+{% end block %} diff --git a/src/templates/packages/name.html b/src/templates/packages/name.html index 5c0e3993..4cb594ef 100644 --- a/src/templates/packages/name.html +++ b/src/templates/packages/name.html @@ -25,6 +25,9 @@
{% for distro in distros %} + {# Fetch Monitoring Status #} + {% set monitoring = backend.monitorings.get_by_distro_and_name(distro, package.name) %} +

{{ distro }}

@@ -48,6 +51,25 @@ {% end %} {% end %}
+ + {# Release Monitoring #} + {% if current_user and current_user.is_admin() %} + {% if monitoring %} + + {% else %} + + {{ _("Enable Release Monitoring") }} + + {% end %} + {% end %} {% end %}
diff --git a/src/web/__init__.py b/src/web/__init__.py index 4bf3cab2..11a6a123 100644 --- a/src/web/__init__.py +++ b/src/web/__init__.py @@ -22,6 +22,7 @@ from . import events from . import jobs from . import keys from . import mirrors +from . import monitorings from . import packages from . import repos from . import search @@ -71,6 +72,9 @@ class Application(tornado.web.Application): # Mirrors "MirrorsList" : mirrors.ListModule, + # Monitorings + "MonitoringsReleasesList" : monitorings.ReleasesListModule, + # Packages "PackageInfo" : packages.InfoModule, "PackageDependencies": packages.DependenciesModule, @@ -198,6 +202,9 @@ class Application(tornado.web.Application): (r"/distros/(?P[A-Za-z0-9\-\.]+)/repos/(?P[A-Za-z0-9\-]+)/sources/(?P[A-Za-z0-9\-]+)", sources.ShowHandler), + # Distro Monitorings + (r"/distros/([A-Za-z0-9\-\.]+)/monitorings/([\w\-_]+)", monitorings.ShowHandler), + # Mirrors (r"/mirrors", mirrors.IndexHandler), (r"/mirrors/create", mirrors.CreateHandler), diff --git a/src/web/monitorings.py b/src/web/monitorings.py new file mode 100644 index 00000000..68b5bc40 --- /dev/null +++ b/src/web/monitorings.py @@ -0,0 +1,44 @@ +############################################################################### +# # +# Pakfire - The IPFire package management system # +# Copyright (C) 2022 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 . # +# # +############################################################################### + +import tornado.web + +from . import base +from . import ui_modules + +class ShowHandler(base.BaseHandler): + def get(self, slug, name): + # Fetch the distribution + distro = self.backend.distros.get_by_slug(slug) + if not distro: + raise tornado.web.HTTPError(404, "Could not find distro %s" % slug) + + # Fetch the monitoring + monitoring = self.backend.monitorings.get_by_distro_and_name(distro, name) + if not monitoring: + raise tornado.web.HTTPError(404, "Could not find monitoring for %s in %s" % (name, distro)) + + self.render("monitorings/show.html", monitoring=monitoring) + + +class ReleasesListModule(ui_modules.UIModule): + def render(self, releases, show_empty=True): + return self.render_string("monitorings/modules/releases-list.html", + releases=releases, show_empty=show_empty)