1 | #!/usr/bin/env python3
|
---|
2 |
|
---|
3 | # LFS ChangeLog generator for trivial package addition, removal, and update
|
---|
4 |
|
---|
5 | from subprocess import Popen, PIPE
|
---|
6 | from urllib.request import urlopen
|
---|
7 | from os import getenv
|
---|
8 |
|
---|
9 | def 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 |
|
---|
19 | def 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 |
|
---|
35 | git_diff = Popen(["git", "diff", "-U999999", "packages.ent"],
|
---|
36 | stdout = PIPE,
|
---|
37 | text = True)
|
---|
38 | stdout, _ = git_diff.communicate()
|
---|
39 |
|
---|
40 | lines = stdout.rstrip().split("\n")
|
---|
41 | ent = [get_entity(i) for i in lines if i[0] != '-']
|
---|
42 | ent = dict(i for i in ent if i)
|
---|
43 |
|
---|
44 | add = set()
|
---|
45 | rem = set()
|
---|
46 |
|
---|
47 | for 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 |
|
---|
59 | upd = add.intersection(rem)
|
---|
60 | add = add.symmetric_difference(upd)
|
---|
61 | rem = rem.symmetric_difference(upd)
|
---|
62 |
|
---|
63 | ticket = {}
|
---|
64 | security = set()
|
---|
65 | url = 'https://wiki.linuxfromscratch.org/lfs/report/1?format=tab'
|
---|
66 | tsv = urlopen(url)
|
---|
67 | for 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 |
|
---|
79 | print("Plain Text:")
|
---|
80 | for (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)
|
---|
87 | for i in rem:
|
---|
88 | print("Remove", i)
|
---|
89 |
|
---|
90 | print("---------------------")
|
---|
91 |
|
---|
92 | print("XML")
|
---|
93 | name = getenv("USER")
|
---|
94 | for (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>')
|
---|