summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorNat Goodspeed <nat@lindenlab.com>2017-09-27 15:25:29 -0400
committerNat Goodspeed <nat@lindenlab.com>2017-09-27 15:25:29 -0400
commit4c6ecac206b79fa472cd1d977ffdda3b82cbe7c7 (patch)
tree1ad2fd8710ca928e6a1b0e061b224abbbac0d558 /scripts
parentd4e939ddb5b9233883a82b974827085dc7a276c1 (diff)
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.
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/packages-formatter.py83
1 files changed, 56 insertions, 27 deletions
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