Take a very sloppy regex mania pass on apps.json generation
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
decentral1se 2021-03-28 11:40:49 +02:00
parent 6f3f4b6779
commit e881f8007e
No known key found for this signature in database
GPG Key ID: 92DAD76BD9567B8A
2 changed files with 43 additions and 15 deletions

3
.gitignore vendored
View File

@ -1,2 +1,3 @@
coverage/
*.json
/.venv
coverage/

View File

@ -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")