Flesh out more of this generation script
	
		
			
	
		
	
	
		
	
		
			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:
		
							
								
								
									
										57
									
								
								app-json.py
									
									
									
									
									
								
							
							
						
						
									
										57
									
								
								app-json.py
									
									
									
									
									
								
							| @ -1,6 +1,6 @@ | ||||
| #!/usr/bin/env python3 | ||||
|  | ||||
| from os import chdir, mkdir | ||||
| from os import chdir, listdir, mkdir | ||||
| from os.path import exists, expanduser | ||||
| from pathlib import Path | ||||
| from shlex import split | ||||
| @ -8,28 +8,69 @@ from subprocess import check_output, run | ||||
|  | ||||
| from requests import get | ||||
|  | ||||
| HOME_PATH = expanduser("~/") | ||||
| CLONES_PATH = Path(f"{HOME_PATH}/.abra/apps").absolute() | ||||
|  | ||||
|  | ||||
| def clone_apps(): | ||||
|     home = expanduser("~/") | ||||
|     clones = Path(f"{home}/.abra/apps").absolute() | ||||
|     if not exists(clones): | ||||
|         mkdir(clones) | ||||
|     if not exists(CLONES_PATH): | ||||
|         mkdir(CLONES_PATH) | ||||
|  | ||||
|     response = get("https://git.autonomic.zone/api/v1/orgs/coop-cloud/repos") | ||||
|     repos = [[p["name"], p["ssh_url"]] for p in response.json()] | ||||
|  | ||||
|     skips = ("organising", "cloud.autonomic.zone", "docs.cloud.autonomic.zone", "abra") | ||||
|  | ||||
|     for name, url in repos: | ||||
|         if name in skips: | ||||
|             continue | ||||
|  | ||||
|         try: | ||||
|             if not exists(f"{clones}/{name}"): | ||||
|                 run(split(f"git clone {url} {clones}/{name}")) | ||||
|                 chdir(f"{clones}/{name}") | ||||
|             if not exists(f"{CLONES_PATH}/{name}"): | ||||
|                 run(split(f"git clone {url} {CLONES_PATH}/{name}")) | ||||
|                 chdir(f"{CLONES_PATH}/{name}") | ||||
|                 if not int(check_output("git branch --list | wc -l", shell=True)): | ||||
|                     run(split("git checkout main")) | ||||
|         except Exception: | ||||
|             pass | ||||
|  | ||||
|  | ||||
| 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 {} | ||||
|  | ||||
|  | ||||
| def main(): | ||||
|     clone_apps() | ||||
|     print(gen_apps_json()) | ||||
|  | ||||
|  | ||||
| if __name__ == "__main__": | ||||
|  | ||||
		Reference in New Issue
	
	Block a user