source: gen-changelog.py@ d98496d

12.0 12.0-rc1 12.1 12.1-rc1 bdubbs/gcc13 multilib renodr/libudev-from-systemd trunk xry111/arm64 xry111/arm64-12.0 xry111/clfs-ng xry111/loongarch xry111/loongarch-12.0 xry111/loongarch-12.1 xry111/mips64el xry111/update-glibc
Last change on this file since d98496d was d98496d, checked in by Xi Ruoyao <xry111@…>, 13 months ago

gen-changelog: Mark security fix correctly

  • Property mode set to 100755
File size: 2.9 KB
Line 
1#!/usr/bin/env python3
2
3# LFS ChangeLog generator for trivial package addition, removal, and update
4
5from subprocess import Popen, PIPE
6from urllib.request import urlopen
7from os import getenv
8
9def get_entity(line):
10 line = line[1:]
11 if not line.startswith("<!ENTITY "):
12 return None
13 quote_pos = line.find(' "')
14 key = line[len("<!ENTITY "):quote_pos]
15 value = line[quote_pos + 2:]
16 value = value[:value.find('"')]
17 return (key, value)
18
19def expand_entity(ent, key):
20 value = ent[key]
21 out = ""
22 sub_ent = ""
23 for c in value:
24 if c == '&':
25 sub_ent = c
26 elif sub_ent:
27 sub_ent += c
28 if c == ';':
29 out += expand_entity(ent, sub_ent[1:-1])
30 sub_ent = ""
31 else:
32 out += c
33 return out
34
35git_diff = Popen(["git", "diff", "-U999999", "packages.ent"],
36 stdout = PIPE,
37 text = True)
38stdout, _ = git_diff.communicate()
39
40lines = stdout.rstrip().split("\n")
41ent = [get_entity(i) for i in lines if i[0] != '-']
42ent = dict(i for i in ent if i)
43
44add = set()
45rem = set()
46
47for l in lines:
48 if l[0] in '+-':
49 pair = get_entity(l)
50 if pair:
51 key, _ = pair
52 if key.endswith('-md5'):
53 pkg = key[:-len('-md5')]
54 if l[0] == '+':
55 add.add(pkg)
56 else:
57 rem.add(pkg)
58
59upd = add.intersection(rem)
60add = add.symmetric_difference(upd)
61rem = rem.symmetric_difference(upd)
62
63ticket = {}
64security = set()
65url = 'https://wiki.linuxfromscratch.org/lfs/report/1?format=tab'
66tsv = urlopen(url)
67for i in tsv:
68 fields = i.decode().split('\t')
69 if len(fields) >= 2:
70 pkg = fields[1].lower()
71 pos = pkg.find(' ')
72 if pos > 0:
73 pkg = pkg[:pos]
74 tic = fields[0]
75 if len(fields) >= 3 and fields[2].startswith("high"):
76 security.add(pkg)
77 ticket[pkg] = tic
78
79print("Plain Text:")
80for (s, act) in [(upd, "Update to "), (add, "Add ")]:
81 for i in s:
82 pkgver = i + "-" + expand_entity(ent, i + "-version")
83 out = act + pkgver
84 if pkgver in ticket:
85 out += ' (#' + ticket[pkgver] + ')'
86 print(out)
87for i in rem:
88 print("Remove", i)
89
90print("---------------------")
91
92print("XML")
93name = getenv("USER")
94for (s, act) in [(upd, "Update to "), (add, "Add ")]:
95 for i in s:
96 print(' <listitem>')
97 pkgver = i + "-" + expand_entity(ent, i + "-version")
98 out = ' <para>[' + name + '] - ' + act + pkgver
99 if pkgver in security:
100 out += " (security fix)"
101 out += "."
102 if pkgver in ticket:
103 out += " Fixes\n "
104 out += "<ulink url='&lfs-ticket-root;" + ticket[pkgver] + "'>#"
105 out += ticket[pkgver] + "</ulink>."
106 out += "</para>"
107 print(out)
108 print(' </listitem>')
Note: See TracBrowser for help on using the repository browser.