summaryrefslogtreecommitdiff
path: root/scripts/packages-formatter.py
diff options
context:
space:
mode:
authorOz Linden <oz@lindenlab.com>2018-01-19 11:18:29 -0500
committerOz Linden <oz@lindenlab.com>2018-01-19 11:18:29 -0500
commita7911c43791a76f0f93f920f527970125afdc730 (patch)
tree99228045170856cf7721e83274bc9d74b45f42a4 /scripts/packages-formatter.py
parent444643aeb0b80fdfbe28e0e2faae56de9d4f6e4a (diff)
parent7acbd8ed8d73c507675d45360df07d232c431a8b (diff)
merge changes for 5.1.0-release
Diffstat (limited to 'scripts/packages-formatter.py')
-rwxr-xr-xscripts/packages-formatter.py95
1 files changed, 65 insertions, 30 deletions
diff --git a/scripts/packages-formatter.py b/scripts/packages-formatter.py
index 928d340b69..b1eef3c721 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,45 +56,74 @@ 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
-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