Adapt the audited publisher refusal changes, derive metadata from the signed APK, and constrain all regression staging to disposable repositories.
40 lines
1.3 KiB
Python
40 lines
1.3 KiB
Python
#!/usr/bin/env python3
|
|
"""Read beta Companion version metadata from the signed APK, never Gradle text."""
|
|
import argparse
|
|
import json
|
|
import re
|
|
import subprocess
|
|
|
|
|
|
def parse_badging(badging):
|
|
packages = [line for line in badging.splitlines() if line.startswith('package:')]
|
|
if len(packages) != 1:
|
|
raise ValueError('Expected exactly one APK package record')
|
|
match = re.match(
|
|
r"^package: name='([^']+)' versionCode='([0-9]+)' versionName='([^']+)'(?: |$)",
|
|
packages[0],
|
|
)
|
|
if not match or match[1] != 'com.archipelago.app.debug':
|
|
raise ValueError('APK is not the existing beta Companion package')
|
|
code = int(match[2])
|
|
name = match[3]
|
|
if not 1 <= code <= 2_100_000_000 or any(ord(c) < 32 for c in name):
|
|
raise ValueError('Invalid APK version metadata')
|
|
return {'versionName': name, 'versionCode': code}
|
|
|
|
|
|
def main():
|
|
parser = argparse.ArgumentParser(description=__doc__)
|
|
parser.add_argument('--aapt', required=True)
|
|
parser.add_argument('apk')
|
|
args = parser.parse_args()
|
|
result = subprocess.run(
|
|
[args.aapt, 'dump', 'badging', args.apk],
|
|
check=True, capture_output=True, text=True, timeout=30,
|
|
)
|
|
print(json.dumps(parse_badging(result.stdout), indent=2))
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|