From 0ad1466acd9475491e2cff84e23428adf50fcdde Mon Sep 17 00:00:00 2001 From: Newbyte Date: Tue, 27 Apr 2021 11:08:11 +0200 Subject: [PATCH] Add release refresher script This script regenerates the tags inside the Appstream XML based on docs/CHANGELOG.md. --- refresh-releases.py | 68 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100755 refresh-releases.py diff --git a/refresh-releases.py b/refresh-releases.py new file mode 100755 index 00000000..107ebe8b --- /dev/null +++ b/refresh-releases.py @@ -0,0 +1,68 @@ +#!/usr/bin/env python3 + +from pathlib import Path +import html +import mistune +import re + + +def get_src_path(): + return str(Path(__file__).resolve().parent) + + +def make_changelog_dict(title): + title_parts = title.split(" ") + + return { + "date": title_parts[2][1:-2], + "version": title_parts[1] + } + + +def make_release_tag(version, date): + return " \n" \ + + +markdown_parser = mistune.Markdown(escape=False) +changelog_title_pattern = re.compile(r"##\ \d\.\d\.\d\ \(\d{4}-\d{2}-\d{2}\)") +changelog_lines = open(get_src_path() + "/docs/CHANGELOG.md", "r").readlines() +changelog_entries = [] + +for line in changelog_lines: + if changelog_title_pattern.match(line): + changelog_entry = make_changelog_dict(line) + changelog_entries.append(changelog_entry) + +appdata_releases = "" + +for entry in changelog_entries: + appdata_releases += make_release_tag(entry["version"], entry["date"]) + +appdata_path = get_src_path() + "/packaging/mirage.appdata.xml" +appdata_lines = open(appdata_path, "r").readlines() +releases_open_pattern = re.compile(r" ") +releases_close_pattern = re.compile(r" ") + +opening_tag_found = False +releases_open_line = 0 +releases_close_line = 0 + +for line in appdata_lines: + if not opening_tag_found: + releases_open_line += 1 + if releases_open_pattern.match(line): + opening_tag_found = True + if releases_close_pattern.match(line): + break + releases_close_line += 1 + +# We need to remove the old release entries since we're inserting +# new ones unconditionally +del appdata_lines[releases_open_line:releases_close_line] +appdata_lines.insert(releases_open_line, appdata_releases) + +with open(appdata_path, "w") as appdata_file: + appdata_lines = "".join(appdata_lines) + appdata_file.write(appdata_lines)