aboutsummaryrefslogtreecommitdiffstats
path: root/gen-changelog.py
diff options
context:
space:
mode:
authorXi Ruoyao <xry111@xry111.site>2023-03-31 22:05:15 +0800
committerXi Ruoyao <xry111@xry111.site>2023-03-31 22:05:15 +0800
commit92dbe964f1e726ddf6589d5083819780f49fdf23 (patch)
treef9d51b857a6f898689f9860f157922f3600366c4 /gen-changelog.py
parent04038ad828fc6299e9392d22c62d535a1940daaa (diff)
Add a script to generate ChangeLog from "git diff"
Diffstat (limited to 'gen-changelog.py')
-rwxr-xr-xgen-changelog.py105
1 files changed, 105 insertions, 0 deletions
diff --git a/gen-changelog.py b/gen-changelog.py
new file mode 100755
index 000000000..91909b254
--- /dev/null
+++ b/gen-changelog.py
@@ -0,0 +1,105 @@
+#!/usr/bin/env python3
+
+# LFS ChangeLog generator for trivial package addition, removal, and update
+
+from subprocess import Popen, PIPE
+from urllib.request import urlopen
+from os import getenv
+
+def get_entity(line):
+ line = line[1:]
+ if not line.startswith("<!ENTITY "):
+ return None
+ quote_pos = line.find(' "')
+ key = line[len("<!ENTITY "):quote_pos]
+ value = line[quote_pos + 2:]
+ value = value[:value.find('"')]
+ return (key, value)
+
+def expand_entity(ent, key):
+ value = ent[key]
+ out = ""
+ sub_ent = ""
+ for c in value:
+ if c == '&':
+ sub_ent = c
+ elif sub_ent:
+ sub_ent += c
+ if c == ';':
+ out += expand_entity(ent, sub_ent[1:-1])
+ sub_ent = ""
+ else:
+ out += c
+ return out
+
+git_diff = Popen(["git", "diff", "-U999999", "packages.ent"],
+ stdout = PIPE,
+ text = True)
+stdout, _ = git_diff.communicate()
+
+lines = stdout.rstrip().split("\n")
+ent = [get_entity(i) for i in lines if i[0] != '-']
+ent = dict(i for i in ent if i)
+
+add = set()
+rem = set()
+
+for l in lines:
+ if l[0] in '+-':
+ pair = get_entity(l)
+ if pair:
+ key, _ = pair
+ if key.endswith('-md5'):
+ pkg = key[:-len('-md5')]
+ if l[0] == '+':
+ add.add(pkg)
+ else:
+ rem.add(pkg)
+
+upd = add.intersection(rem)
+add = add.symmetric_difference(upd)
+rem = rem.symmetric_difference(upd)
+
+ticket = {}
+security = set()
+url = 'https://wiki.linuxfromscratch.org/lfs/report/1?format=tab'
+tsv = urlopen(url)
+for i in tsv:
+ fields = i.decode().split('\t')
+ if len(fields) >= 2:
+ pkg = fields[1].lower()
+ pos = pkg.find(' ')
+ if pos > 0:
+ pkg = pkg[:pos]
+ tic = fields[0]
+ sec = len(fields) >= 3 and fields[2].startswith("high")
+ ticket[pkg] = tic
+ security.add(pkg)
+
+print("Plain Text:")
+for (s, act) in [(upd, "Update to "), (add, "Add ")]:
+ for i in s:
+ pkgver = i + "-" + expand_entity(ent, i + "-version")
+ out = act + pkgver
+ if pkgver in ticket:
+ out += ' (#' + ticket[pkgver] + ')'
+ print(out)
+for i in rem:
+ print("Remove", i)
+
+print("---------------------")
+
+print("XML")
+name = getenv("USER")
+for (s, act) in [(upd, "Update to "), (add, "Add ")]:
+ for i in s:
+ print(' <listitem>')
+ pkgver = i + "-" + expand_entity(ent, i + "-version")
+ out = ' <para>[' + name + '] - ' + act + pkgver + "."
+ if pkgver in ticket:
+ out += " Fixes\n "
+ out += "<ulink url='&lfs-ticket-root;" + ticket[pkgver] + "'>#"
+ out += ticket[pkgver] + "</ulink>."
+ out += "</para>"
+ print(out)
+ print(' </listitem>')