summaryrefslogtreecommitdiffstats
path: root/doc/gen_pkgdiff.py
diff options
context:
space:
mode:
authorThomas Lundström <thomas.lundstrom@enea.com>2016-06-03 18:15:09 +0200
committerThomas Lundström <thomas.lundstrom@enea.com>2016-06-03 18:18:25 +0200
commitcaefc34c829e8f22c180d3c269efda27a255cbb2 (patch)
tree3589a155748ec0292d3c56f9f9740786ed5d2a38 /doc/gen_pkgdiff.py
parent7faac5b18133cdc7965dfc98cebea3457ca3a1be (diff)
downloadel_manifests-standard-caefc34c829e8f22c180d3c269efda27a255cbb2.tar.gz
Updated release info
Diffstat (limited to 'doc/gen_pkgdiff.py')
-rw-r--r--doc/gen_pkgdiff.py167
1 files changed, 167 insertions, 0 deletions
diff --git a/doc/gen_pkgdiff.py b/doc/gen_pkgdiff.py
new file mode 100644
index 0000000..acfbadc
--- /dev/null
+++ b/doc/gen_pkgdiff.py
@@ -0,0 +1,167 @@
1###############################################################################
2#
3# Diff two licenses.xml files. Splits the result in three sets:
4# 1) Removed
5# Packages present in the old file, but not in the new.
6#
7# 2) Added
8# Packages present in the new file, but not in the old.
9#
10# 3) Changed
11# Packages present in both files, but with different versions.
12#
13# Note that packages with the unchanged version is not listed.
14#
15# The output is presented as XML code printed to stdout.
16#
17###############################################################################
18
19import sys
20import subprocess
21import xml.etree.ElementTree as ET
22
23def get_pkgs(file_spec):
24 if file_spec.find(":") >= 0:
25 cmd = ("git", "show", file_spec)
26 root = ET.fromstring(subprocess.check_output(cmd))
27
28 else:
29 root = ET.parse(file_spec)
30
31 for node in root.iter("section"):
32 if "id" in node.attrib:
33 if node.attrib["id"] == "licenses_packages":
34 break
35
36 else:
37 return None
38
39 for node in node:
40 if node.tag == "informaltable":
41 break
42 else:
43 return None
44
45 tab = node[0][-1]
46
47 plist = dict()
48 for row in tab:
49 pname = row[0].text
50 pver = row[1].text
51 if not pname in plist:
52 plist[pname] = set()
53
54 plist[pname].add(pver)
55
56 return set(plist), plist
57
58#----------------------------------------
59
60if len(sys.argv) != 3:
61 sys.stderr.write("Usage:\n")
62 sys.stderr.write(" %s " % sys.argv[0])
63 sys.stderr.write("<new license file> <old license file>\n")
64 sys.stderr.write("\n")
65 sys.stderr.write(" E.g.:\n")
66 sys.stderr.write(" %s " % sys.argv[0])
67 sys.stderr.write("licenses-5.0-ppc.xml licenses.xml\n")
68 exit()
69
70new_file, old_file = sys.argv[1:3]
71
72sys.stderr.write("New license file : %s\n" % new_file)
73sys.stderr.write("Prev license file : %s\n" % old_file)
74
75old_pset, old_pdict = get_pkgs(old_file)
76new_pset, new_pdict = get_pkgs(new_file)
77
78added = new_pset - old_pset # Set subtraction
79removed = old_pset - new_pset # Set subtraction
80common = old_pset & new_pset
81changed = [ p for p in common if old_pdict[p] != new_pdict[p] ]
82
83print '<?xml version="1.0" encoding="ISO-8859-1"?>'
84print '<!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"'
85print '"http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">'
86print '<section id="relinfo-package-set-changes">'
87print ' <title>Changes in the Set of Provided Package</title>'
88print ' <para>'
89print ' This section describes changes in the provided packages.'
90print ' </para>'
91print ' <section id="relinfo-added-packages">'
92print ' <title>Added Packages</title>'
93print ' <informaltable>'
94print ' <tgroup cols="2">'
95print ' <thead>'
96print ' <row>'
97print ' <entry>Package</entry>'
98print ' <entry>Version(s)</entry>'
99print ' </row>'
100print ' </thead>'
101print ' <tbody>'
102
103for p in sorted(list(added)):
104 print ' <row>'
105 print ' <entry>%s</entry>' % p
106 print ' <entry>%s</entry>' % ", ".join(sorted(new_pdict[p]))
107 print ' </row>'
108
109print ' </tbody>'
110print ' </tgroup>'
111print ' </informaltable>'
112print ' </section>'
113
114print ' <section id="relinfo-removed-packages">'
115print ' <title>Removed Packages</title>'
116print ' <informaltable>'
117print ' <tgroup cols="2">'
118print ' <thead>'
119print ' <row>'
120print ' <entry>Package</entry>'
121print ' <entry>Version(s)</entry>'
122print ' </row>'
123print ' </thead>'
124print ' <tbody>'
125for p in sorted(list(removed)):
126 print ' <row>'
127 print ' <entry>%s</entry>' % p
128 print ' <entry>%s</entry>' % ", ".join(sorted(old_pdict[p]))
129 print ' </row>'
130print ' </tbody>'
131print ' </tgroup>'
132print ' </informaltable>'
133print ' </section>'
134
135print ' <section id="relinfo-changed-packages">'
136print ' <title>Changed Package Versions</title>'
137print ' <informaltable>'
138print ' <tgroup cols="3">'
139print ' <thead>'
140print ' <row>'
141print ' <entry>Package</entry>'
142print ' <entry>Previous Version(s)</entry>'
143print ' <entry>New Version(s)</entry>'
144print ' </row>'
145print ' </thead>'
146print ' <tbody>'
147for p in sorted(list(changed)):
148 print ' <row>'
149 print ' <entry>%s</entry>' % p
150 print ' <entry>%s</entry>' % ", ".join(sorted(old_pdict[p]))
151 print ' <entry>%s</entry>' % ", ".join(sorted(new_pdict[p]))
152 print ' </row>'
153
154print ' </tbody>'
155print ' </tgroup>'
156print ' </informaltable>'
157print ' </section>'
158print '</section>'
159
160sys.stderr.write("Package Summary:\n")
161sys.stderr.write(" Prev file : %3d\n" % len(old_pset))
162sys.stderr.write(" New file : %3d\n" % len(new_pset))
163sys.stderr.write(" Added : %3d\n" % len(added))
164sys.stderr.write(" Removed : %3d\n" % len(removed))
165sys.stderr.write(" Changed : %3d\n" % len(changed))
166sys.stderr.write(" Unchanged : %3d\n" % (len(common) - len(changed)))
167sys.stderr.write("Done\n")