feat: convert toml files recursively
	
		
			
	
		
	
	
		
	
		
			All checks were successful
		
		
	
	
		
			
				
	
				build / build (push) Successful in 2m28s
				
			
		
		
	
	
				
					
				
			
		
			All checks were successful
		
		
	
	build / build (push) Successful in 2m28s
				
			This commit is contained in:
		
							parent
							
								
									73f2581a31
								
							
						
					
					
						commit
						68628c0eae
					
				|  | @ -1,5 +1,4 @@ | ||||||
| import json | import json | ||||||
| import os |  | ||||||
| from pathlib import Path | from pathlib import Path | ||||||
| 
 | 
 | ||||||
| import inquirer | import inquirer | ||||||
|  | @ -51,18 +50,19 @@ def convert(root: Path = Path(".")) -> None: | ||||||
|     Convert given dir of JOJ3 toml config files to JOJ3 json config files |     Convert given dir of JOJ3 toml config files to JOJ3 json config files | ||||||
|     """ |     """ | ||||||
|     logger.info(f"Converting files in {root.absolute()}") |     logger.info(f"Converting files in {root.absolute()}") | ||||||
|     repo_toml_path = os.path.join(root, "repo.toml") |     repo_toml_path = root / "repo.toml" | ||||||
|     # TODO: loop through all dirs to find all task.toml |     repo_obj = rtoml.loads( | ||||||
|     task_toml_path = os.path.join(root, "task.toml") |         repo_toml_path.read_text() if repo_toml_path.exists() else "" | ||||||
|     result_json_path = os.path.join(root, "task.json") |     ) | ||||||
|     with open(repo_toml_path) as repo_file: |     for task_toml_path in root.glob("**/*.toml"): | ||||||
|         repo_toml = repo_file.read() |         toml_name = task_toml_path.name.removesuffix(".toml") | ||||||
|     with open(task_toml_path) as task_file: |         if toml_name == "repo": | ||||||
|         task_toml = task_file.read() |             continue | ||||||
|     repo_obj = rtoml.loads(repo_toml) |         result_json_path = task_toml_path.parent / f"{toml_name}.json" | ||||||
|     task_obj = rtoml.loads(task_toml) |         logger.info(f"Converting {task_toml_path} to {result_json_path}") | ||||||
|  |         task_obj = rtoml.loads(task_toml_path.read_text()) | ||||||
|         result_model = convert_conf(repo.Config(**repo_obj), task.Config(**task_obj)) |         result_model = convert_conf(repo.Config(**repo_obj), task.Config(**task_obj)) | ||||||
|         result_dict = result_model.model_dump(by_alias=True) |         result_dict = result_model.model_dump(by_alias=True) | ||||||
|     with open(result_json_path, "w") as result_file: |         with result_json_path.open("w") as result_file: | ||||||
|             json.dump(result_dict, result_file, ensure_ascii=False, indent=4) |             json.dump(result_dict, result_file, ensure_ascii=False, indent=4) | ||||||
|             result_file.write("\n") |             result_file.write("\n") | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user