From a5ce75a29bd5514a1cb5129afaf550898338c282 Mon Sep 17 00:00:00 2001 From: decentral1se Date: Fri, 26 Mar 2021 01:14:14 +0100 Subject: [PATCH] First stab at the apps JSON generation script See https://git.autonomic.zone/coop-cloud/abra/issues/121. --- app-json.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100755 app-json.py diff --git a/app-json.py b/app-json.py new file mode 100755 index 0000000..675e0b8 --- /dev/null +++ b/app-json.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python3 + +from os import chdir, mkdir +from os.path import exists, expanduser +from pathlib import Path +from shlex import split +from subprocess import check_output, run + +from requests import get + + +def clone_apps(): + home = expanduser("~/") + clones = Path(f"{home}/.abra/apps").absolute() + if not exists(clones): + mkdir(clones) + + response = get("https://git.autonomic.zone/api/v1/orgs/coop-cloud/repos") + repos = [[p["name"], p["ssh_url"]] for p in response.json()] + for name, url in repos: + try: + run(split(f"git clone {url} {clones}/{name}")) + chdir(f"{clones}/{name}") + if not check_output("git branch --list | wc -l", shell=True): + run(split("git checkout main")) + except Exception: + pass + + +def main(): + clone_apps() + + +if __name__ == "__main__": + main()