From cf421f9217d6c8f1ce67db81cb7a72c455aec367 Mon Sep 17 00:00:00 2001 From: "Juan J. Martinez" Date: Sat, 4 May 2024 16:22:42 +0100 Subject: Moved to self-hosting - add a tool to generate a release feed (atom) - add a doc on how to contribute - update README --- tools/atom.py | 106 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100755 tools/atom.py (limited to 'tools') diff --git a/tools/atom.py b/tools/atom.py new file mode 100755 index 0000000..1a174f7 --- /dev/null +++ b/tools/atom.py @@ -0,0 +1,106 @@ +#!/usr/bin/env python3 + +# script to generate an atom feed from CHANGES.md + +import re +from datetime import datetime, timezone, time + +release = re.compile("^## Release ([0-9]+\\.[0-9]+\\.[0-9]+) - ([0-9]+-[0-9]+-[0-9]+)$") + +title = "ubox MXS lib releases" +base_url = "https://www.usebox.net/jjm/ubox-msx-lib/changes.html" +release_url = "https://git.usebox.net/ubox-msx-lib/tag/" +feed_file = "releases.xml" +author = "jjm" +tz = timezone.utc + + +def get_entries(changes): + entries = [] + + with open(changes, "rt") as fd: + lines = fd.readlines() + + i = 0 + while i < len(lines): + line = lines[i] + m = release.match(line) + if m: + version = m.group(1) + # because timezones and summer time, use 1am + updated_on = datetime.combine( + datetime.fromisoformat(m.group(2)), time(1, 0, 0) + ).astimezone(tz) + body = "" + i += 1 + while i < len(lines) and (lines[i] == "" or lines[i][0] != "#"): + body += lines[i] + i += 1 + + entries.append(dict(version=version, updated_on=updated_on, body=body)) + else: + i += 1 + + entries.sort(key=lambda o: o["updated_on"], reverse=True) + return entries + + +def to_atom(post): + return """\ + + {title} + + {url} + {updated_on} + +
+
{body}
+

Download available at ubox MSX lib website.

+
+
+
\n""".format( + title="Released ubox MSX lib " + post["version"], + url=base_url + "#release-" + post["version"] + "---" + post["updated_on"].date().isoformat(), + version=post["version"], + release_url=release_url, + updated_on=post["updated_on"].isoformat(), + body=post["body"].rstrip() + "\n", + ) + + +def gen_atom(entries): + + updated_on = datetime(1900, 1, 1, tzinfo=tz) + posts_atom = [] + for post in entries: + if post["updated_on"] > updated_on: + updated_on = post["updated_on"] + + posts_atom.append(to_atom(post)) + + return "\n".join( + [ + """""", + """""", + """%s""" % title, + """""" % base_url, + """""" % (base_url + feed_file), + """%s""" % updated_on.isoformat(), + """%s""" % base_url, + """""", + """ %s""" % author, + """""", + ] + + posts_atom + + [""] + ) + + +def main(): + entries = get_entries("../CHANGES.md") + with open(feed_file, "wt") as fd: + fd.write(gen_atom(entries)) + + +if __name__ == "__main__": + main() -- cgit v1.2.3