From fb47a5a09bf61dd4020e0486f321a675fdfb8cf4 Mon Sep 17 00:00:00 2001 From: Jiri Kyjovsky Date: Mon, 12 Dec 2022 18:03:12 +0100 Subject: [PATCH 1/2] frontend: add command for managing warning banner --- .../coprs_frontend/commands/warning_banner.py | 51 +++++++++++++++++++ frontend/coprs_frontend/coprs/constants.py | 6 +++ .../coprs/context_processors.py | 4 +- .../coprs/templates/banner-include.html | 16 ++++++ frontend/coprs_frontend/manage.py | 2 + 5 files changed, 76 insertions(+), 3 deletions(-) create mode 100755 frontend/coprs_frontend/commands/warning_banner.py create mode 100644 frontend/coprs_frontend/coprs/constants.py create mode 100755 frontend/coprs_frontend/coprs/templates/banner-include.html diff --git a/frontend/coprs_frontend/commands/warning_banner.py b/frontend/coprs_frontend/commands/warning_banner.py new file mode 100755 index 000000000..1cb8410b1 --- /dev/null +++ b/frontend/coprs_frontend/commands/warning_banner.py @@ -0,0 +1,51 @@ +""" +Command for managing warning banner on the top of frontend page. +""" + + +import os +import sys +from pathlib import Path + +import click +from jinja2 import Template + +from coprs.constants import BANNER_LOCATION + + +@click.command() +@click.option("--outage_time", "-o", default=None, help="start time of the outage") +@click.option("--ticket", "-t", default=None, help="fedora infra ticket ID") +@click.option("--rest", default=None, help="additional code") +@click.option("--remove", is_flag=True, show_default=True, default=False, help="removes banner") +def warning_banner(outage_time, ticket, rest, remove): + """ + Adds a banner to Copr's frontend page with outage warning. `outage_time` or `rest` is required. + + In case you need to schedule regular outage, fill in only `outage_time` and `ticket`. In case + you need to add something else, please use the `rest` parameter to dump to warning banner + some additional information. This can be just some text or html code. + `rest` parameter can be used as a standalone option just for showing some warning banner + with specific information. It can be also piece of HTML code. + """ + if remove: + if outage_time or ticket or rest: + print( + "Error: can't remove banner with `outage_time` or `ticket` or `rest`", + file=sys.stderr, + ) + return + + if os.path.exists(BANNER_LOCATION): + os.remove(BANNER_LOCATION) + return + + if outage_time is None and rest is None: + print("Error: `outage_time` or `rest` should be present.", file=sys.stderr) + return + + with open(BANNER_LOCATION, "w", encoding="UTF-8") as banner: + banner_path_template = Path(__file__).parent / "../coprs/templates/banner-include.html" + with banner_path_template.open() as banner_template: + template = Template(banner_template.read()) + banner.write(template.render(outage_time=outage_time, ticket=ticket, rest=rest)) diff --git a/frontend/coprs_frontend/coprs/constants.py b/frontend/coprs_frontend/coprs/constants.py new file mode 100644 index 000000000..4f51c2511 --- /dev/null +++ b/frontend/coprs_frontend/coprs/constants.py @@ -0,0 +1,6 @@ +""" +File which contains only constants. Nothing else. +""" + + +BANNER_LOCATION = "/var/lib/copr/data/banner-include.html" diff --git a/frontend/coprs_frontend/coprs/context_processors.py b/frontend/coprs_frontend/coprs/context_processors.py index e40f93125..7eaeb2421 100644 --- a/frontend/coprs_frontend/coprs/context_processors.py +++ b/frontend/coprs_frontend/coprs/context_processors.py @@ -2,12 +2,10 @@ import flask from coprs import app +from coprs.constants import BANNER_LOCATION from coprs.helpers import current_url -BANNER_LOCATION = "/var/lib/copr/banner-include.html" - - @app.context_processor def include_banner(): if os.path.exists(BANNER_LOCATION): diff --git a/frontend/coprs_frontend/coprs/templates/banner-include.html b/frontend/coprs_frontend/coprs/templates/banner-include.html new file mode 100755 index 000000000..3c82b2a4d --- /dev/null +++ b/frontend/coprs_frontend/coprs/templates/banner-include.html @@ -0,0 +1,16 @@ + diff --git a/frontend/coprs_frontend/manage.py b/frontend/coprs_frontend/manage.py index d8590a624..4ad2fa0ba 100755 --- a/frontend/coprs_frontend/manage.py +++ b/frontend/coprs_frontend/manage.py @@ -40,6 +40,7 @@ import commands.delete_orphans import commands.fixup_unnoticed_chroots import commands.chroots_template +import commands.warning_banner from coprs import app @@ -90,6 +91,7 @@ "clean_old_builds", "delete_orphans", "delete_dirs", + "warning_banner", ] From 749de739cfe45fdad2bea98365bc22a5140c8ee2 Mon Sep 17 00:00:00 2001 From: Jiri Kyjovsky Date: Fri, 16 Dec 2022 17:19:40 +0100 Subject: [PATCH 2/2] docs: document release-banner command --- doc/how_to_release_copr.rst | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/doc/how_to_release_copr.rst b/doc/how_to_release_copr.rst index 5cd0dd975..47866f331 100644 --- a/doc/how_to_release_copr.rst +++ b/doc/how_to_release_copr.rst @@ -10,6 +10,15 @@ good to know what's ahead. Keep amending this page if you find something not matching reality or expectations. +Create warning banner about release +----------------------------------- + + +Use script in frontend's ``manage.py`` to announce an outage:: + + ./manage.py warning-banner --outage_time "2022-12-31 13:00-16:00 UTC" --ticket 1234 + + Pre-release ----------- @@ -422,6 +431,11 @@ It is often good idea to put new (filtered) ``%changelogs`` entries there. Final steps ........... +Remove the warning banner from frontend page by:: + + ./manage.py warning-banner --remove + + Check if the `MODIFIED bugs `_ (that are not ON_QA) are fixed in released Copr or not, move them ON_QA.