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.master
parent
d4e939ddb5
commit
4c6ecac206
|
|
@ -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)
|
||||
else:
|
||||
sys.exit("Unrecognized --versions output: %s" % line)
|
||||
info=dict(versions={}, copyrights={})
|
||||
dups=dict(versions=set(), copyrights=set())
|
||||
|
||||
copyright={}
|
||||
def add_info(key, pkg, lines):
|
||||
if pkg not in info[key]:
|
||||
info[key][pkg] = '\n'.join(lines)
|
||||
else:
|
||||
dups[key].add(pkg)
|
||||
|
||||
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
|
||||
|
|
|
|||
Loading…
Reference in New Issue