summaryrefslogtreecommitdiffstats
path: root/doc/gen_pkgdiff.py
diff options
context:
space:
mode:
Diffstat (limited to 'doc/gen_pkgdiff.py')
-rwxr-xr-xdoc/gen_pkgdiff.py222
1 files changed, 0 insertions, 222 deletions
diff --git a/doc/gen_pkgdiff.py b/doc/gen_pkgdiff.py
deleted file mode 100755
index ddacf44..0000000
--- a/doc/gen_pkgdiff.py
+++ /dev/null
@@ -1,222 +0,0 @@
1#!/bin/python
2###############################################################################
3#
4# Diff two licenses.xml files. There are two cases:
5# * Two arguments
6# In this case, the two arguments are the two files to compare
7#
8# * No arguments
9# In this casem the license files are specified by the following
10# parameters in pardoc-distro.xml:
11# - prev_baseline
12# - prev_lic_file
13# - new_lic_file
14#
15# The result is presented as three sets:
16# 1) Removed
17# Packages present in the previous file, but not in the new.
18#
19# 2) Added
20# Packages present in the new file, but not in the previous.
21#
22# 3) Changed
23# Packages present in both files, but with different versions. If more than
24# one version of a package is included, then all difference in the version
25# set causes the package to be listed as changed.
26# E.g.
27# (v1) -> (v2)
28# (v1, v2) -> (v2, v3)
29#
30# Note that packages with the unchanged version is not listed.
31#
32# The output is presented as XML code printed to stdout. A summary is printed
33# to STDERR at the end.
34#
35###############################################################################
36
37import os
38import sys
39import subprocess as sp
40import xml.etree.ElementTree as ET
41import re
42
43repo_root = sp.check_output(["git", "rev-parse", "--show-toplevel"]).rstrip()
44script_root = os.path.dirname(os.path.realpath(__file__))
45param_file = os.path.join(script_root, "docsrc_common/pardoc-distro.xml")
46
47def get_param(param_name):
48 pat = re.compile("%s.*>([^<>]+)</" % param_name)
49
50 with open(param_file) as f:
51 for line in f:
52 m = pat.search(line)
53 if m:
54 return m.group(1)
55
56 return None
57
58def get_pkgs(file_spec):
59 if file_spec.find(":") >= 0:
60 s = sp.check_output(("git", "show", file_spec))
61 else:
62 f = open(file_spec)
63 s = f.read()
64 f.close()
65 del f
66
67 # ET can't handle some special quotes
68 for old, new in (("&rdquor;", "&quot;"), ("&rdquo;", "&quot;")):
69 s = s.replace(old, new)
70
71 root = ET.fromstring(s)
72
73 for node in root.iter("section"):
74 if "id" in node.attrib:
75 if node.attrib["id"] == "licenses_packages":
76 break
77
78 else:
79 return None
80
81 for node in node:
82 if node.tag == "informaltable":
83 break
84 else:
85 return None
86
87 tab = node[0][-1]
88
89 plist = dict()
90 for row in tab:
91 pname = row[0].text
92 pver = row[1].text
93 if not pname in plist:
94 plist[pname] = set()
95
96 plist[pname].add(pver)
97
98 return set(plist), plist
99
100#----------------------------------------
101
102
103if len(sys.argv) == 3:
104 new_file, prev_file = sys.argv[1:3]
105
106elif len(sys.argv) == 1:
107 prev_baseline = get_param("prev_baseline")
108 prev_lic_file = get_param("prev_lic_file")
109 new_lic_file = get_param("new_lic_file")
110
111 new_file = os.path.relpath(os.path.join(repo_root, new_lic_file))
112 prev_file = "%s:%s" % (prev_baseline, prev_lic_file)
113
114else:
115 sys.stderr.write("Usage:\n")
116 sys.stderr.write(" 1) %s\n" % sys.argv[0])
117 sys.stderr.write(" 2) %s " % sys.argv[0])
118 sys.stderr.write("<new license file> <old license file>\n")
119 sys.stderr.write("\n")
120 sys.stderr.write("In case 1, the files are specified using the following\n")
121 sys.stderr.write("parameters in pardoc-distro.xml:\n")
122 sys.stderr.write(" - prev_baseline\n")
123 sys.stderr.write(" - prev_lic_file\n")
124 sys.stderr.write(" - new_lic_file\n")
125 exit()
126
127sys.stderr.write("New license file : %s\n" % new_file)
128sys.stderr.write("Prev license file : %s\n" % prev_file)
129
130old_pset, old_pdict = get_pkgs(prev_file)
131new_pset, new_pdict = get_pkgs(new_file)
132
133added = new_pset - old_pset # Set subtraction
134removed = old_pset - new_pset # Set subtraction
135common = old_pset & new_pset
136changed = [ p for p in common if old_pdict[p] != new_pdict[p] ]
137
138print '<?xml version="1.0" encoding="ISO-8859-1"?>'
139print '<!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"'
140print '"http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">'
141print '<section id="relinfo-package-set-changes">'
142print ' <title>Changes in the Set of Provided Package</title>'
143print ' <para>'
144print ' This section describes changes in the provided packages.'
145print ' </para>'
146print ' <section id="relinfo-added-packages">'
147print ' <title>Added Packages</title>'
148print ' <informaltable>'
149print ' <tgroup cols="2">'
150print ' <thead>'
151print ' <row>'
152print ' <entry>Package</entry>'
153print ' <entry>Version(s)</entry>'
154print ' </row>'
155print ' </thead>'
156print ' <tbody>'
157
158for p in sorted(list(added)):
159 print ' <row>'
160 print ' <entry>%s</entry>' % p
161 print ' <entry>%s</entry>' % ", ".join(sorted(new_pdict[p]))
162 print ' </row>'
163
164print ' </tbody>'
165print ' </tgroup>'
166print ' </informaltable>'
167print ' </section>'
168
169print ' <section id="relinfo-removed-packages">'
170print ' <title>Removed Packages</title>'
171print ' <informaltable>'
172print ' <tgroup cols="2">'
173print ' <thead>'
174print ' <row>'
175print ' <entry>Package</entry>'
176print ' <entry>Version(s)</entry>'
177print ' </row>'
178print ' </thead>'
179print ' <tbody>'
180for p in sorted(list(removed)):
181 print ' <row>'
182 print ' <entry>%s</entry>' % p
183 print ' <entry>%s</entry>' % ", ".join(sorted(old_pdict[p]))
184 print ' </row>'
185print ' </tbody>'
186print ' </tgroup>'
187print ' </informaltable>'
188print ' </section>'
189
190print ' <section id="relinfo-changed-packages">'
191print ' <title>Changed Package Versions</title>'
192print ' <informaltable>'
193print ' <tgroup cols="3">'
194print ' <thead>'
195print ' <row>'
196print ' <entry>Package</entry>'
197print ' <entry>Previous Version(s)</entry>'
198print ' <entry>New Version(s)</entry>'
199print ' </row>'
200print ' </thead>'
201print ' <tbody>'
202for p in sorted(list(changed)):
203 print ' <row>'
204 print ' <entry>%s</entry>' % p
205 print ' <entry>%s</entry>' % ", ".join(sorted(old_pdict[p]))
206 print ' <entry>%s</entry>' % ", ".join(sorted(new_pdict[p]))
207 print ' </row>'
208
209print ' </tbody>'
210print ' </tgroup>'
211print ' </informaltable>'
212print ' </section>'
213print '</section>'
214
215sys.stderr.write("Package Summary:\n")
216sys.stderr.write(" Prev file : %3d\n" % len(old_pset))
217sys.stderr.write(" New file : %3d\n" % len(new_pset))
218sys.stderr.write(" Added : %3d\n" % len(added))
219sys.stderr.write(" Removed : %3d\n" % len(removed))
220sys.stderr.write(" Changed : %3d\n" % len(changed))
221sys.stderr.write(" Unchanged : %3d\n" % (len(common) - len(changed)))
222sys.stderr.write("Done\n")