#!/usr/bin/env python3 """Print the metadata after the owner supplies public URLs and licensing.""" import argparse import re from pathlib import Path from urllib.parse import urlsplit p = argparse.ArgumentParser(description=__doc__) p.add_argument('--repo', required=True, help='Public anonymous HTTPS Git clone URL') p.add_argument('--source', required=True, help='Public source browsing/download page') p.add_argument('--license', required=True, choices=['Apache-2.0', 'GPL-3.0-or-later']) a = p.parse_args() root = Path(__file__).resolve().parents[1] if not (root / 'LICENSE').is_file() or 'PENDING' in (root / 'LICENSING.txt').read_text(): p.error('Finalize the owner-approved LICENSE and LICENSING.txt first.') for url in [a.repo, a.source]: u = urlsplit(url) if u.scheme != 'https' or not u.hostname or u.username or u.password or any(c.isspace() for c in url) or any(c in url for c in "'\"#"): p.error('Use public HTTPS URLs without credentials, fragments, quotes or whitespace.') text = (root / 'packaging/com.glosira.app.fdroid.yml.in').read_text() for name, value in [('LICENSE', a.license), ('REPO_URL', a.repo), ('SOURCE_URL', a.source)]: text = text.replace('@' + name + '@', value) build = (root / 'app/build.gradle').read_text() version = re.search(r"versionName\s+'([^']+)'", build).group(1) code = re.search(r'versionCode\s+(\d+)', build).group(1) text = re.sub(r"versionName: '[^']+'", "versionName: '" + version + "'", text) text = re.sub(r'versionCode: \d+', 'versionCode: ' + code, text) text = re.sub(r'commit: v[^\n]+', 'commit: v' + version, text) text = re.sub(r"CurrentVersion: '[^']+'", "CurrentVersion: '" + version + "'", text) text = re.sub(r'CurrentVersionCode: \d+', 'CurrentVersionCode: ' + code, text) print(text, end='')