Skip to content
Snippets Groups Projects
Commit 4c6ecac2 authored by Nat Goodspeed's avatar Nat Goodspeed
Browse files

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.
parent d4e939dd
No related branches found
No related tags found
No related merge requests found
...@@ -62,39 +62,68 @@ def autobuild(*args): ...@@ -62,39 +62,68 @@ def autobuild(*args):
# no exceptions yet, let caller read stdout # no exceptions yet, let caller read stdout
return child.stdout return child.stdout
version={} info=dict(versions={}, copyrights={})
versions=autobuild('install', '--versions') dups=dict(versions=set(), copyrights=set())
for line in versions:
pkg_info = pkg_line.match(line) def add_info(key, pkg, lines):
if pkg_info: if pkg not in info[key]:
pkg = pkg_info.group(1) info[key][pkg] = '\n'.join(lines)
if pkg not in version:
version[pkg] = pkg_info.group(2).strip()
else:
sys.exit("Duplicate version for %s" % pkg)
else: else:
sys.exit("Unrecognized --versions output: %s" % line) dups[key].add(pkg)
copyright={} versions=autobuild('install', '--versions')
copyrights=autobuild('install', '--copyrights') copyrights=autobuild('install', '--copyrights')
viewer_copyright = copyrights.readline() # first line is the copyright for the viewer itself viewer_copyright = copyrights.readline() # first line is the copyright for the viewer itself
for line in copyrights:
pkg_info = pkg_line.match(line) # Two different autobuild outputs, but we treat them essentially the same way:
if pkg_info: # populating each into a dict; each a subdict of 'info'.
pkg = pkg_info.group(1) for key, rawdata in ("versions", versions), ("copyrights", copyrights):
if pkg not in copyright: lines = iter(rawdata)
copyright[pkg] = pkg_info.group(2).strip() try:
else: line = next(lines)
sys.exit("Duplicate copyright for %s" % pkg) except StopIteration:
# rawdata is completely empty? okay...
pass
else: 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 "%s %s" % (args.channel, args.version)
print viewer_copyright print viewer_copyright
for pkg in sorted(version): version = list(info['versions'].items())
print ': '.join([pkg, version[pkg]]) version.sort()
if pkg in copyright: for pkg, pkg_version in version:
print copyright[pkg] print ': '.join([pkg, pkg_version])
else: try:
print info['copyrights'][pkg]
except KeyError:
sys.exit("No copyright for %s" % pkg) sys.exit("No copyright for %s" % pkg)
print '' print
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment