From 3a8aa2d13d4d362847ce2ec16376907e7f562500 Mon Sep 17 00:00:00 2001 From: Oz Linden Date: Fri, 2 Dec 2016 10:59:06 -0500 Subject: add viewer channel and version to the beginning of the About box Licenses information --- scripts/packages-formatter.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'scripts/packages-formatter.py') diff --git a/scripts/packages-formatter.py b/scripts/packages-formatter.py index 928d340b69..f91f5819b7 100755 --- a/scripts/packages-formatter.py +++ b/scripts/packages-formatter.py @@ -29,6 +29,12 @@ import sys import errno import re import subprocess +import argparse + +parser = argparse.ArgumentParser(description='Format dependency version and copyright information for the viewer About box content') +parser.add_argument('channel', help='viewer channel name') +parser.add_argument('version', help='viewer version number') +args = parser.parse_args() _autobuild=os.getenv('AUTOBUILD', 'autobuild') @@ -50,9 +56,8 @@ def autobuild(*args): # Don't attempt to interpret anything but ENOENT raise # Here it's ENOENT: subprocess can't find the autobuild executable. - print >>sys.stderr, "packages-formatter on %s: can't run autobuild:\n%s\n%s" % \ - (sys.platform, ' '.join(command), err) - sys.exit(1) + sys.exit("packages-formatter on %s: can't run autobuild:\n%s\n%s" % \ + (sys.platform, ' '.join(command), err)) # no exceptions yet, let caller read stdout return child.stdout @@ -84,6 +89,7 @@ for line in copyrights: else: sys.exit("Unrecognized --copyrights output: %s" % line) +print "%s %s" % (args.channel, args.version) print viewer_copyright for pkg in sorted(version): print ': '.join([pkg, version[pkg]]) -- cgit v1.2.3 From 4c6ecac206b79fa472cd1d977ffdda3b82cbe7c7 Mon Sep 17 00:00:00 2001 From: Nat Goodspeed Date: Wed, 27 Sep 2017 15:25:29 -0400 Subject: MAINT-7081: Make packages-formatter.py handle multi-line copyrights. The nghttp2 autobuild package has copyright information that embeds a newline. autobuild install --copyrights correctly produces that information onto two lines. But that means packages-formatter.py must process any lines that do not match its expected 'packagename: copyright' pattern as the continuation of the preceding package's copyright information. Since the processing for autobuild install --versions is so very similar, fold both into the same outer loop. Also report all duplicates for any package, instead of stopping at the first. --- scripts/packages-formatter.py | 83 +++++++++++++++++++++++++++++-------------- 1 file changed, 56 insertions(+), 27 deletions(-) (limited to 'scripts/packages-formatter.py') diff --git a/scripts/packages-formatter.py b/scripts/packages-formatter.py index f91f5819b7..b1eef3c721 100755 --- a/scripts/packages-formatter.py +++ b/scripts/packages-formatter.py @@ -62,39 +62,68 @@ def autobuild(*args): # no exceptions yet, let caller read stdout return child.stdout -version={} -versions=autobuild('install', '--versions') -for line in versions: - pkg_info = pkg_line.match(line) - if pkg_info: - pkg = pkg_info.group(1) - if pkg not in version: - version[pkg] = pkg_info.group(2).strip() - else: - sys.exit("Duplicate version for %s" % pkg) +info=dict(versions={}, copyrights={}) +dups=dict(versions=set(), copyrights=set()) + +def add_info(key, pkg, lines): + if pkg not in info[key]: + info[key][pkg] = '\n'.join(lines) else: - sys.exit("Unrecognized --versions output: %s" % line) + dups[key].add(pkg) -copyright={} +versions=autobuild('install', '--versions') copyrights=autobuild('install', '--copyrights') viewer_copyright = copyrights.readline() # first line is the copyright for the viewer itself -for line in copyrights: - pkg_info = pkg_line.match(line) - if pkg_info: - pkg = pkg_info.group(1) - if pkg not in copyright: - copyright[pkg] = pkg_info.group(2).strip() - else: - sys.exit("Duplicate copyright for %s" % pkg) + +# Two different autobuild outputs, but we treat them essentially the same way: +# populating each into a dict; each a subdict of 'info'. +for key, rawdata in ("versions", versions), ("copyrights", copyrights): + lines = iter(rawdata) + try: + line = next(lines) + except StopIteration: + # rawdata is completely empty? okay... + pass else: - sys.exit("Unrecognized --copyrights output: %s" % line) + pkg_info = pkg_line.match(line) + # The first line for each package must match pkg_line. + if not pkg_info: + sys.exit("Unrecognized --%s output: %r" % (key, line)) + # Only the very first line in rawdata MUST match; for the rest of + # rawdata, matching the regexp is how we recognize the start of the + # next package. + while True: # iterate over packages in rawdata + pkg = pkg_info.group(1) + pkg_lines = [pkg_info.group(2).strip()] + for line in lines: + pkg_info = pkg_line.match(line) + if pkg_info: + # we hit the start of the next package data + add_info(key, pkg, pkg_lines) + break + else: + # no package prefix: additional line for same package + pkg_lines.append(line.rstrip()) + else: + # last package in the output -- finished 'lines' + add_info(key, pkg, pkg_lines) + break + +# Now that we've run through all of both outputs -- are there duplicates? +if any(pkgs for pkgs in dups.values()): + for key, pkgs in dups.items(): + if pkgs: + print >>sys.stderr, "Duplicate %s for %s" % (key, ", ".join(pkgs)) + sys.exit(1) print "%s %s" % (args.channel, args.version) print viewer_copyright -for pkg in sorted(version): - print ': '.join([pkg, version[pkg]]) - if pkg in copyright: - print copyright[pkg] - else: +version = list(info['versions'].items()) +version.sort() +for pkg, pkg_version in version: + print ': '.join([pkg, pkg_version]) + try: + print info['copyrights'][pkg] + except KeyError: sys.exit("No copyright for %s" % pkg) - print '' + print -- cgit v1.2.3