From f9245a4d59a7c8938685c3df74d13c2841c027f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Bompard?= Date: Wed, 5 Jun 2024 10:21:02 +0200 Subject: [PATCH] Drop Whitenoise, Flask can serve static files by itself MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Aurélien Bompard --- mirrormanager2/app.py | 5 ----- mirrormanager2/templates/fedora/host.html | 2 +- mirrormanager2/views.py | 7 +++++++ poetry.lock | 16 +--------------- pyproject.toml | 1 - utility/mirrormanager2.spec | 1 - 6 files changed, 9 insertions(+), 23 deletions(-) diff --git a/mirrormanager2/app.py b/mirrormanager2/app.py index 1536e2df5..442c42480 100644 --- a/mirrormanager2/app.py +++ b/mirrormanager2/app.py @@ -31,7 +31,6 @@ from flask_admin import Admin from flask_oidc import OpenIDConnect from sqlalchemy.orm import configure_mappers -from whitenoise import WhiteNoise from mirrormanager2 import __version__, local_auth from mirrormanager2.admin import register_views as register_admin_views @@ -133,8 +132,4 @@ def create_app(config=None): XMLRPC.connect(app, "/xmlrpc") - # More static files - app.wsgi_app = WhiteNoise(app.wsgi_app) - app.wsgi_app.add_files(os.path.join(app.config["MM_LOG_DIR"], "crawler"), prefix="crawler/") - return app diff --git a/mirrormanager2/templates/fedora/host.html b/mirrormanager2/templates/fedora/host.html index da6b24724..4be8f8432 100644 --- a/mirrormanager2/templates/fedora/host.html +++ b/mirrormanager2/templates/fedora/host.html @@ -77,7 +77,7 @@

Host {{ host.name }}

{% if host.private %}Last Checked In: {{ host.last_checked_in or '-' }}
{% endif %} {% if not host.private %}Last Crawled: {% if host.last_crawled %} {{ host.last_crawled - }} [Log] {% else %} - {% endif %}
+ }} [Log] {% else %} - {% endif %}
Last Crawl Duration: {{ host.last_crawl_duration }} seconds {% if host.crawl_failures > 0 %}
Number of consecutive crawl failures: {{ host.crawl_failures }} {% endif %}{% endif %}

diff --git a/mirrormanager2/views.py b/mirrormanager2/views.py index b7c3c1515..e24d05c38 100644 --- a/mirrormanager2/views.py +++ b/mirrormanager2/views.py @@ -1,4 +1,5 @@ import datetime +import os import re import flask @@ -1255,3 +1256,9 @@ def propagation(repo_id): return flask.render_template( "propagation.html", repos=repos, repo=repo, labels=labels, datasets=datasets ) + + +@views.route("/crawler/.log") +def crawler_log(self, host_id): + crawler_log_dir = os.path.join(flask.current_app.config["MM_LOG_DIR"], "crawler") + return flask.utils.send_from_directory(crawler_log_dir, f"{host_id}.log", max_age=None) diff --git a/poetry.lock b/poetry.lock index e8783f431..9297121f6 100644 --- a/poetry.lock +++ b/poetry.lock @@ -2436,20 +2436,6 @@ MarkupSafe = ">=2.1.1" [package.extras] watchdog = ["watchdog (>=2.3)"] -[[package]] -name = "whitenoise" -version = "6.6.0" -description = "Radically simplified static file serving for WSGI applications" -optional = false -python-versions = ">=3.8" -files = [ - {file = "whitenoise-6.6.0-py3-none-any.whl", hash = "sha256:b1f9db9bf67dc183484d760b99f4080185633136a273a03f6436034a41064146"}, - {file = "whitenoise-6.6.0.tar.gz", hash = "sha256:8998f7370973447fac1e8ef6e8ded2c5209a7b1f67c1012866dbcd09681c3251"}, -] - -[package.extras] -brotli = ["Brotli"] - [[package]] name = "wrapt" version = "1.16.0" @@ -2723,4 +2709,4 @@ deploy = ["gunicorn", "psycopg2"] [metadata] lock-version = "2.0" python-versions = "^3.9" -content-hash = "5f2697d9979c7f4367a16827a42d0ace0aeb719d9c10d4c01228e288e14f97ff" +content-hash = "bda59a16c34095861ea7537a32e32a33c35e1097620dce940e6375d41e26f649" diff --git a/pyproject.toml b/pyproject.toml index 5dae94a3f..1a1268ae4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -60,7 +60,6 @@ click = "^8.1.7" geoip2 = "^4.7.0" gunicorn = {version = "^21.2.0", optional = true} psycopg2 = {version = "^2.9.9", optional = true} -whitenoise = "^6.6.0" rich = "^13.7.0" mrtparse = "^2.2.0" requests = "^2.31.0" diff --git a/utility/mirrormanager2.spec b/utility/mirrormanager2.spec index 14976c1f1..f2b064714 100644 --- a/utility/mirrormanager2.spec +++ b/utility/mirrormanager2.spec @@ -31,7 +31,6 @@ BuildRequires: python%{python_pkgversion}-fedora-messaging BuildRequires: python%{python_pkgversion}-sqlalchemy-helpers BuildRequires: python%{python_pkgversion}-click BuildRequires: python%{python_pkgversion}-geoip2 -BuildRequires: python%{python_pkgversion}-whitenoise BuildRequires: python%{python_pkgversion}-rich BuildRequires: python%{python_pkgversion}-mrtparse BuildRequires: python%{python_pkgversion}-requests