diff options
author | Thomas Lundström <thomas.lundstrom@enea.com> | 2016-06-03 18:15:09 +0200 |
---|---|---|
committer | Thomas Lundström <thomas.lundstrom@enea.com> | 2016-06-03 18:18:25 +0200 |
commit | caefc34c829e8f22c180d3c269efda27a255cbb2 (patch) | |
tree | 3589a155748ec0292d3c56f9f9740786ed5d2a38 /doc/gen_pkgdiff.py | |
parent | 7faac5b18133cdc7965dfc98cebea3457ca3a1be (diff) | |
download | el_manifests-standard-caefc34c829e8f22c180d3c269efda27a255cbb2.tar.gz |
Updated release info
Diffstat (limited to 'doc/gen_pkgdiff.py')
-rw-r--r-- | doc/gen_pkgdiff.py | 167 |
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 | |||
19 | import sys | ||
20 | import subprocess | ||
21 | import xml.etree.ElementTree as ET | ||
22 | |||
23 | def 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 | |||
60 | if 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 | |||
70 | new_file, old_file = sys.argv[1:3] | ||
71 | |||
72 | sys.stderr.write("New license file : %s\n" % new_file) | ||
73 | sys.stderr.write("Prev license file : %s\n" % old_file) | ||
74 | |||
75 | old_pset, old_pdict = get_pkgs(old_file) | ||
76 | new_pset, new_pdict = get_pkgs(new_file) | ||
77 | |||
78 | added = new_pset - old_pset # Set subtraction | ||
79 | removed = old_pset - new_pset # Set subtraction | ||
80 | common = old_pset & new_pset | ||
81 | changed = [ p for p in common if old_pdict[p] != new_pdict[p] ] | ||
82 | |||
83 | print '<?xml version="1.0" encoding="ISO-8859-1"?>' | ||
84 | print '<!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"' | ||
85 | print '"http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">' | ||
86 | print '<section id="relinfo-package-set-changes">' | ||
87 | print ' <title>Changes in the Set of Provided Package</title>' | ||
88 | print ' <para>' | ||
89 | print ' This section describes changes in the provided packages.' | ||
90 | print ' </para>' | ||
91 | print ' <section id="relinfo-added-packages">' | ||
92 | print ' <title>Added Packages</title>' | ||
93 | print ' <informaltable>' | ||
94 | print ' <tgroup cols="2">' | ||
95 | print ' <thead>' | ||
96 | print ' <row>' | ||
97 | print ' <entry>Package</entry>' | ||
98 | print ' <entry>Version(s)</entry>' | ||
99 | print ' </row>' | ||
100 | print ' </thead>' | ||
101 | print ' <tbody>' | ||
102 | |||
103 | for 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 | |||
109 | print ' </tbody>' | ||
110 | print ' </tgroup>' | ||
111 | print ' </informaltable>' | ||
112 | print ' </section>' | ||
113 | |||
114 | print ' <section id="relinfo-removed-packages">' | ||
115 | print ' <title>Removed Packages</title>' | ||
116 | print ' <informaltable>' | ||
117 | print ' <tgroup cols="2">' | ||
118 | print ' <thead>' | ||
119 | print ' <row>' | ||
120 | print ' <entry>Package</entry>' | ||
121 | print ' <entry>Version(s)</entry>' | ||
122 | print ' </row>' | ||
123 | print ' </thead>' | ||
124 | print ' <tbody>' | ||
125 | for 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>' | ||
130 | print ' </tbody>' | ||
131 | print ' </tgroup>' | ||
132 | print ' </informaltable>' | ||
133 | print ' </section>' | ||
134 | |||
135 | print ' <section id="relinfo-changed-packages">' | ||
136 | print ' <title>Changed Package Versions</title>' | ||
137 | print ' <informaltable>' | ||
138 | print ' <tgroup cols="3">' | ||
139 | print ' <thead>' | ||
140 | print ' <row>' | ||
141 | print ' <entry>Package</entry>' | ||
142 | print ' <entry>Previous Version(s)</entry>' | ||
143 | print ' <entry>New Version(s)</entry>' | ||
144 | print ' </row>' | ||
145 | print ' </thead>' | ||
146 | print ' <tbody>' | ||
147 | for 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 | |||
154 | print ' </tbody>' | ||
155 | print ' </tgroup>' | ||
156 | print ' </informaltable>' | ||
157 | print ' </section>' | ||
158 | print '</section>' | ||
159 | |||
160 | sys.stderr.write("Package Summary:\n") | ||
161 | sys.stderr.write(" Prev file : %3d\n" % len(old_pset)) | ||
162 | sys.stderr.write(" New file : %3d\n" % len(new_pset)) | ||
163 | sys.stderr.write(" Added : %3d\n" % len(added)) | ||
164 | sys.stderr.write(" Removed : %3d\n" % len(removed)) | ||
165 | sys.stderr.write(" Changed : %3d\n" % len(changed)) | ||
166 | sys.stderr.write(" Unchanged : %3d\n" % (len(common) - len(changed))) | ||
167 | sys.stderr.write("Done\n") | ||