2021-03-26 00:14:14 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
2021-03-26 19:48:08 +00:00
|
|
|
from os import chdir, listdir, mkdir
|
2021-03-26 00:14:14 +00:00
|
|
|
from os.path import exists, expanduser
|
|
|
|
from pathlib import Path
|
|
|
|
from shlex import split
|
|
|
|
from subprocess import check_output, run
|
|
|
|
|
|
|
|
from requests import get
|
|
|
|
|
2021-03-26 19:48:08 +00:00
|
|
|
HOME_PATH = expanduser("~/")
|
|
|
|
CLONES_PATH = Path(f"{HOME_PATH}/.abra/apps").absolute()
|
|
|
|
|
2021-03-26 00:14:14 +00:00
|
|
|
|
|
|
|
def clone_apps():
|
2021-03-26 19:48:08 +00:00
|
|
|
if not exists(CLONES_PATH):
|
|
|
|
mkdir(CLONES_PATH)
|
2021-03-26 00:14:14 +00:00
|
|
|
|
|
|
|
response = get("https://git.autonomic.zone/api/v1/orgs/coop-cloud/repos")
|
|
|
|
repos = [[p["name"], p["ssh_url"]] for p in response.json()]
|
2021-03-26 19:48:08 +00:00
|
|
|
|
|
|
|
skips = ("organising", "cloud.autonomic.zone", "docs.cloud.autonomic.zone", "abra")
|
|
|
|
|
2021-03-26 00:14:14 +00:00
|
|
|
for name, url in repos:
|
2021-03-26 19:48:08 +00:00
|
|
|
if name in skips:
|
|
|
|
continue
|
|
|
|
|
2021-03-26 00:14:14 +00:00
|
|
|
try:
|
2021-03-26 19:48:08 +00:00
|
|
|
if not exists(f"{CLONES_PATH}/{name}"):
|
|
|
|
run(split(f"git clone {url} {CLONES_PATH}/{name}"))
|
|
|
|
chdir(f"{CLONES_PATH}/{name}")
|
2021-03-26 19:21:37 +00:00
|
|
|
if not int(check_output("git branch --list | wc -l", shell=True)):
|
|
|
|
run(split("git checkout main"))
|
2021-03-26 00:14:14 +00:00
|
|
|
except Exception:
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
2021-03-26 19:48:08 +00:00
|
|
|
def gen_apps_json():
|
|
|
|
apps_json = {}
|
|
|
|
|
|
|
|
for app in listdir(CLONES_PATH):
|
|
|
|
app_path = f"{CLONES_PATH}/{app}"
|
|
|
|
chdir(app_path)
|
|
|
|
|
|
|
|
output = check_output("git tag --list", shell=True)
|
|
|
|
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(),
|
|
|
|
"versions": get_app_versions(),
|
|
|
|
}
|
|
|
|
|
|
|
|
return apps_json
|
|
|
|
|
|
|
|
|
|
|
|
def get_app_features():
|
|
|
|
return {}
|
|
|
|
|
|
|
|
|
|
|
|
def get_app_versions():
|
|
|
|
return {}
|
|
|
|
|
|
|
|
|
2021-03-26 00:14:14 +00:00
|
|
|
def main():
|
|
|
|
clone_apps()
|
2021-03-26 19:48:08 +00:00
|
|
|
print(gen_apps_json())
|
2021-03-26 00:14:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|