From e881f8007e604b3f387ced04f3ea8bf4c6ea3a9d Mon Sep 17 00:00:00 2001 From: decentral1se Date: Sun, 28 Mar 2021 11:40:49 +0200 Subject: [PATCH] Take a very sloppy regex mania pass on apps.json generation --- .gitignore | 3 ++- app-json.py | 55 +++++++++++++++++++++++++++++++++++++++-------------- 2 files changed, 43 insertions(+), 15 deletions(-) diff --git a/.gitignore b/.gitignore index 2451898..bf2498b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ -coverage/ +*.json /.venv +coverage/ diff --git a/app-json.py b/app-json.py index b179dac..0daeaeb 100755 --- a/app-json.py +++ b/app-json.py @@ -1,8 +1,10 @@ #!/usr/bin/env python3 -from os import chdir, listdir, mkdir +from json import dump +from os import chdir, getcwd, listdir, mkdir from os.path import exists, expanduser from pathlib import Path +from re import findall, search from shlex import split from subprocess import check_output, run @@ -46,32 +48,57 @@ def gen_apps_json(): tags = output.strip().decode("utf-8") if not tags: - print(f"Skipping {app} because there are no tags") continue for tag in tags: apps_json[app] = { "category": "apps", "repository": f"https://git.autonomic.zone/coop-cloud/{app}.git", - "features": get_app_features(), + "features": get_app_features(app_path), "versions": get_app_versions(), } return apps_json -def get_app_features(): - return {} +def get_app_features(app_path): + features = {} + + with open(f"{app_path}/README.md", "r") as handle: + contents = handle.read() + + for match in findall(r"\*\*.*\s\*", contents): + title = search(r"\*\*.*\*\*", match).group().replace("*", "").lower() + if title == "image": + value = { + "image": search(r"(?<=`).*(?=`)", match).group(), + "url": search(r"(?<=\().*(?=\))", match).group(), + "rating": "", + "source": "", + } + else: + value = match.split(":")[-1].replace("*", "").strip() + features[title] = value + + return features -def get_app_versions(): - return {} +def get_app_versions(app_path): + versions = {} + + chdir(app_path) + tags = check_output(f"git tag --list").strip() + for tag in tags: + # TODO + # checkout that tag in the local git branch + # parse all service images via yq or other magic + # lookup the digest with skopeo + pass + + return versions -def main(): - clone_apps() - print(gen_apps_json()) - - -if __name__ == "__main__": - main() +clone_apps() +with open(f"{getcwd()}/abra-apps.json", "w", encoding="utf-8") as handle: + dump(gen_apps_json(), handle, ensure_ascii=False, indent=4) +print("Output saved to abra-apps.json")