Take a very sloppy regex mania pass on apps.json generation
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
6f3f4b6779
commit
e881f8007e
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,2 +1,3 @@
|
|||||||
coverage/
|
*.json
|
||||||
/.venv
|
/.venv
|
||||||
|
coverage/
|
||||||
|
55
app-json.py
55
app-json.py
@ -1,8 +1,10 @@
|
|||||||
#!/usr/bin/env python3
|
#!/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 os.path import exists, expanduser
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
from re import findall, search
|
||||||
from shlex import split
|
from shlex import split
|
||||||
from subprocess import check_output, run
|
from subprocess import check_output, run
|
||||||
|
|
||||||
@ -46,32 +48,57 @@ def gen_apps_json():
|
|||||||
tags = output.strip().decode("utf-8")
|
tags = output.strip().decode("utf-8")
|
||||||
|
|
||||||
if not tags:
|
if not tags:
|
||||||
print(f"Skipping {app} because there are no tags")
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
for tag in tags:
|
for tag in tags:
|
||||||
apps_json[app] = {
|
apps_json[app] = {
|
||||||
"category": "apps",
|
"category": "apps",
|
||||||
"repository": f"https://git.autonomic.zone/coop-cloud/{app}.git",
|
"repository": f"https://git.autonomic.zone/coop-cloud/{app}.git",
|
||||||
"features": get_app_features(),
|
"features": get_app_features(app_path),
|
||||||
"versions": get_app_versions(),
|
"versions": get_app_versions(),
|
||||||
}
|
}
|
||||||
|
|
||||||
return apps_json
|
return apps_json
|
||||||
|
|
||||||
|
|
||||||
def get_app_features():
|
def get_app_features(app_path):
|
||||||
return {}
|
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():
|
def get_app_versions(app_path):
|
||||||
return {}
|
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()
|
||||||
clone_apps()
|
with open(f"{getcwd()}/abra-apps.json", "w", encoding="utf-8") as handle:
|
||||||
print(gen_apps_json())
|
dump(gen_apps_json(), handle, ensure_ascii=False, indent=4)
|
||||||
|
print("Output saved to abra-apps.json")
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
main()
|
|
||||||
|
Reference in New Issue
Block a user