From 82345bb71a756f33529bfc1bb7b22a2c46d1ba6e Mon Sep 17 00:00:00 2001 From: Thomas Lundström Date: Fri, 10 Jun 2016 09:24:18 +0200 Subject: gen_pkgdiff.py can now use pardoc-distro.xml to specify input files --- doc/gen_pkgdiff.py | 78 +++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 63 insertions(+), 15 deletions(-) (limited to 'doc/gen_pkgdiff.py') diff --git a/doc/gen_pkgdiff.py b/doc/gen_pkgdiff.py index 7dd8c73..5a13311 100644 --- a/doc/gen_pkgdiff.py +++ b/doc/gen_pkgdiff.py @@ -1,14 +1,30 @@ ############################################################################### # -# Diff two licenses.xml files. Splits the result in three sets: +# Diff two licenses.xml files. There are two cases: +# * Two arguments +# In this case, the two arguments are the two files to compare +# +# * No arguments +# In this casem the license files are specified by the following +# parameters in pardoc-distro.xml: +# - prev_baseline +# - prev_lic_file +# - new_lic_file +# +# The result is presented as three sets: # 1) Removed -# Packages present in the old file, but not in the new. +# Packages present in the previous file, but not in the new. # # 2) Added -# Packages present in the new file, but not in the old. +# Packages present in the new file, but not in the previous. # # 3) Changed -# Packages present in both files, but with different versions. +# Packages present in both files, but with different versions. If more than +# one version of a package is included, then all difference in the version +# set causes the package to be listed as changed. +# E.g. +# (v1) -> (v2) +# (v1, v2) -> (v2, v3) # # Note that packages with the unchanged version is not listed. # @@ -17,13 +33,30 @@ # ############################################################################### +import os import sys -import subprocess +import subprocess as sp import xml.etree.ElementTree as ET +import re + +repo_root = sp.check_output(["git", "rev-parse", "--show-toplevel"]).rstrip() +script_root = os.path.dirname(os.path.realpath(__file__)) +param_file = os.path.join(script_root, "docsrc_common/pardoc-distro.xml") + +def get_param(param_name): + pat = re.compile("%s.*>([^<>]+)= 0: - s = subprocess.check_output(("git", "show", file_spec)) + s = sp.check_output(("git", "show", file_spec)) else: f = open(file_spec) s = f.read() @@ -65,22 +98,37 @@ def get_pkgs(file_spec): #---------------------------------------- -if len(sys.argv) != 3: + +if len(sys.argv) == 3: + new_file, prev_file = sys.argv[1:3] + +elif len(sys.argv) == 1: + prev_baseline = get_param("prev_baseline") + prev_lic_file = get_param("prev_lic_file") + new_lic_file = get_param("new_lic_file") + + new_file = os.path.relpath(os.path.join(repo_root, new_lic_file)) + prev_file = "%s:%s" % (prev_baseline, prev_lic_file) + print prev_file + print new_file + +else: sys.stderr.write("Usage:\n") - sys.stderr.write(" %s " % sys.argv[0]) + sys.stderr.write(" 1) %s\n" % sys.argv[0]) + sys.stderr.write(" 2) %s " % sys.argv[0]) sys.stderr.write(" \n") sys.stderr.write("\n") - sys.stderr.write(" E.g.:\n") - sys.stderr.write(" %s " % sys.argv[0]) - sys.stderr.write("licenses-5.0-ppc.xml licenses.xml\n") + sys.stderr.write("In case 1, the files are specified using the following\n") + sys.stderr.write("parameters in pardoc-distro.xml:\n") + sys.stderr.write(" - prev_baseline\n") + sys.stderr.write(" - prev_lic_file\n") + sys.stderr.write(" - new_lic_file\n") exit() -new_file, old_file = sys.argv[1:3] - sys.stderr.write("New license file : %s\n" % new_file) -sys.stderr.write("Prev license file : %s\n" % old_file) +sys.stderr.write("Prev license file : %s\n" % prev_file) -old_pset, old_pdict = get_pkgs(old_file) +old_pset, old_pdict = get_pkgs(prev_file) new_pset, new_pdict = get_pkgs(new_file) added = new_pset - old_pset # Set subtraction -- cgit v1.2.3-54-g00ecf