From 1f35a6a61ef817f2fb7e74d06d62e1861c974204 Mon Sep 17 00:00:00 2001 From: fossdd Date: Mon, 8 Mar 2021 17:04:28 +0000 Subject: [PATCH 1/2] Initial check-fastlane-as-fallback tool --- tools/check-fastlane-as-fallback.py | 75 +++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100755 tools/check-fastlane-as-fallback.py diff --git a/tools/check-fastlane-as-fallback.py b/tools/check-fastlane-as-fallback.py new file mode 100755 index 000000000000..67914965ce5f --- /dev/null +++ b/tools/check-fastlane-as-fallback.py @@ -0,0 +1,75 @@ +#!/usr/bin/env python3 +# pylint: disable=invalid-name + +""" +Check for every metadata if upstream provides fastlane metadata at the latest specified commit +If yes then remove description and summary from app metadata +""" + +import os +import re +import glob +import requests +import yaml + +for f in glob.glob("metadata/*.yml"): + with open(f) as fp: + data = yaml.safe_load(fp) + + if "Builds" not in data: + continue + if "Summary" not in data: + if "Description" not in data: + continue + if "Description" not in data: + if "Summary" not in data: + continue + + builds = data["Builds"] + latest_build = builds[len(builds) - 1] + if "commit" not in latest_build: + continue + latest_commit = latest_build["commit"] + if "Repo" not in data: + continue + repo = data["Repo"] + repo_domain_search = re.search( + r"([a-z0-9A-Z]\.)*[a-z0-9-]+\.([a-z0-9]{2,24})+(\.co\.([a-z0-9]{2,24})|\.([a-z0-9]{2,24}))*", # pylint: disable=line-too-long + repo, + ) + if not repo_domain_search: + continue + repo_domain = repo_domain_search.group() + + check_url = None + + if repo_domain == "github.com": + check_url = ( + repo.replace(".git", "") + + "/raw/" + + latest_commit + + "/fastlane/metadata/android/en-US/full_description.txt" + ) + + if repo_domain == "gitlab.com": + check_url = ( + repo.replace(".git", "") + + "/-/raw/" + + latest_commit + + "/fastlane/metadata/android/en-US/full_description.txt" + ) + + if not check_url: + continue + + request = requests.get(check_url) + + if (request.status_code == 200) or (request.status_code == 302): + print(f) + with open(f, "w") as output: + if "Description" in data: + del data["Description"] + if "Summary" in data: + del data["Summary"] + output.write(yaml.dump(data)) + os.system("fdroid rewritemeta " + f[9:][:-4]) -- GitLab From 806dee6a8e1c4a35612b1c4b70db0b9f259240e1 Mon Sep 17 00:00:00 2001 From: fossdd Date: Mon, 8 Mar 2021 17:22:37 +0000 Subject: [PATCH 2/2] check-fastlane-as-fallback: Parse arguments and only run check on this file --- tools/check-fastlane-as-fallback.py | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/tools/check-fastlane-as-fallback.py b/tools/check-fastlane-as-fallback.py index 67914965ce5f..4b16450d4bda 100755 --- a/tools/check-fastlane-as-fallback.py +++ b/tools/check-fastlane-as-fallback.py @@ -7,38 +7,43 @@ If yes then remove description and summary from app metadata """ import os +import sys import re import glob import requests import yaml -for f in glob.glob("metadata/*.yml"): + +def run(f): # pylint: disable=too-many-return-statements,too-many-branches + """ + Run the check and write to file specified as arg + """ with open(f) as fp: data = yaml.safe_load(fp) if "Builds" not in data: - continue + return if "Summary" not in data: if "Description" not in data: - continue + return if "Description" not in data: if "Summary" not in data: - continue + return builds = data["Builds"] latest_build = builds[len(builds) - 1] if "commit" not in latest_build: - continue + return latest_commit = latest_build["commit"] if "Repo" not in data: - continue + return repo = data["Repo"] repo_domain_search = re.search( r"([a-z0-9A-Z]\.)*[a-z0-9-]+\.([a-z0-9]{2,24})+(\.co\.([a-z0-9]{2,24})|\.([a-z0-9]{2,24}))*", # pylint: disable=line-too-long repo, ) if not repo_domain_search: - continue + return repo_domain = repo_domain_search.group() check_url = None @@ -60,7 +65,7 @@ for f in glob.glob("metadata/*.yml"): ) if not check_url: - continue + return request = requests.get(check_url) @@ -73,3 +78,10 @@ for f in glob.glob("metadata/*.yml"): del data["Summary"] output.write(yaml.dump(data)) os.system("fdroid rewritemeta " + f[9:][:-4]) + + +if len(sys.argv) == 1: + for file in glob.glob("metadata/*.yml"): + run(file) +else: + run(sys.argv[1]) -- GitLab