Remove unneeded PATH entries.
[lfs.git] / gen-changelog.py
blob3bf6bc06490e1269cc78e687df089aad759532f6
1 #!/usr/bin/env python3
3 # LFS ChangeLog generator for trivial package addition, removal, and update
5 from subprocess import Popen, PIPE
6 from urllib.request import urlopen
7 from os import getenv
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)
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
35 git_diff = Popen(["git", "diff", "-U999999", "packages.ent"],
36 stdout = PIPE,
37 text = True)
38 stdout, _ = git_diff.communicate()
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)
44 add = set()
45 rem = set()
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)
59 upd = add.intersection(rem)
60 add = add.symmetric_difference(upd)
61 rem = rem.symmetric_difference(upd)
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
79 hold_ticket = {'vim': '4500', 'iana-etc': '5006'}
81 print("Plain Text:")
82 for (s, act) in [(upd, "Update to "), (add, "Add ")]:
83 for i in s:
84 pkgver = i + "-" + expand_entity(ent, i + "-version")
85 out = act + pkgver
86 if pkgver in ticket:
87 out += ' (#' + ticket[pkgver] + ')'
88 elif i in hold_ticket:
89 out += ' (#' + hold_ticket[i] + ')'
90 print("-", out)
91 for i in rem:
92 print("-", "Remove", i)
94 print("---------------------")
96 print("XML")
97 name = getenv("USER")
98 for (s, act) in [(upd, "Update to "), (add, "Add ")]:
99 for i in s:
100 print(' <listitem>')
101 pkgver = i + "-" + expand_entity(ent, i + "-version")
102 out = ' <para>[' + name + '] - ' + act + pkgver
103 if pkgver in security:
104 out += " (security fix)"
105 out += "."
107 pkg_ticket = None
108 if pkgver in ticket:
109 out += " Fixes\n "
110 pkg_ticket = ticket[pkgver]
111 elif i in hold_ticket:
112 out += " Addresses\n "
113 pkg_ticket = hold_ticket[i]
115 if pkg_ticket:
116 out += "<ulink url='&lfs-ticket-root;" + pkg_ticket + "'>#"
117 out += pkg_ticket + "</ulink>."
118 out += "</para>"
119 print(out)
120 print(' </listitem>')