feat: convert joj1 cli
This commit is contained in:
		
							parent
							
								
									806bb47a61
								
							
						
					
					
						commit
						3b0b36c539
					
				|  | @ -5,9 +5,11 @@ from pathlib import Path | ||||||
| import inquirer | import inquirer | ||||||
| import rtoml | import rtoml | ||||||
| import typer | import typer | ||||||
|  | import yaml | ||||||
| 
 | 
 | ||||||
| from joj3_config_generator.convert import convert as convert_conf | from joj3_config_generator.convert import convert as convert_conf | ||||||
| from joj3_config_generator.models import RepoConfig, TaskConfig | from joj3_config_generator.convert import convert_joj1 as convert_joj1_conf | ||||||
|  | from joj3_config_generator.models import joj1, repo, task | ||||||
| from joj3_config_generator.utils.logger import logger | from joj3_config_generator.utils.logger import logger | ||||||
| 
 | 
 | ||||||
| app = typer.Typer(add_completion=False) | app = typer.Typer(add_completion=False) | ||||||
|  | @ -31,11 +33,16 @@ def create(toml: typer.FileTextWrite) -> None: | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| @app.command() | @app.command() | ||||||
| def convert_joj1(yaml: typer.FileText, toml: typer.FileTextWrite) -> None: | def convert_joj1(yaml_file: typer.FileText, toml_file: typer.FileTextWrite) -> None: | ||||||
|     """ |     """ | ||||||
|     Convert a JOJ1 yaml config file to JOJ3 toml config file |     Convert a JOJ1 yaml config file to JOJ3 toml config file | ||||||
|     """ |     """ | ||||||
|     logger.info("Converting") |     logger.info(f"Converting yaml file {yaml_file}") | ||||||
|  |     joj1_obj = yaml.safe_load(yaml_file.read()) | ||||||
|  |     joj1_model = joj1.Config(**joj1_obj) | ||||||
|  |     task_model = convert_joj1_conf(joj1_model) | ||||||
|  |     result_dict = task_model.model_dump(by_alias=True) | ||||||
|  |     toml_file.write(rtoml.dumps(result_dict)) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| @app.command() | @app.command() | ||||||
|  | @ -54,7 +61,7 @@ def convert(root: Path = Path(".")) -> None: | ||||||
|         task_toml = task_file.read() |         task_toml = task_file.read() | ||||||
|     repo_obj = rtoml.loads(repo_toml) |     repo_obj = rtoml.loads(repo_toml) | ||||||
|     task_obj = rtoml.loads(task_toml) |     task_obj = rtoml.loads(task_toml) | ||||||
|     result_model = convert_conf(RepoConfig(**repo_obj), TaskConfig(**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 open(result_json_path, "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) | ||||||
|  |  | ||||||
|  | @ -11,10 +11,10 @@ def read_convert_joj1_files(case_name: str) -> Tuple[joj1.Config, Dict[str, Any] | ||||||
|     root = os.path.dirname(os.path.realpath(__file__)) |     root = os.path.dirname(os.path.realpath(__file__)) | ||||||
|     task_yaml_path = os.path.join(root, case_name, "task.yaml") |     task_yaml_path = os.path.join(root, case_name, "task.yaml") | ||||||
|     task_toml_path = os.path.join(root, case_name, "task.toml") |     task_toml_path = os.path.join(root, case_name, "task.toml") | ||||||
|     with open(task_yaml_path) as repo_file: |     with open(task_yaml_path) as f: | ||||||
|         task_yaml = repo_file.read() |         task_yaml = f.read() | ||||||
|     with open(task_toml_path) as task_file: |     with open(task_toml_path) as f: | ||||||
|         task_toml = task_file.read() |         task_toml = f.read() | ||||||
|     joj1_obj = yaml.safe_load(task_yaml) |     joj1_obj = yaml.safe_load(task_yaml) | ||||||
|     task_obj = rtoml.loads(task_toml) |     task_obj = rtoml.loads(task_toml) | ||||||
|     return joj1.Config(**joj1_obj), task_obj |     return joj1.Config(**joj1_obj), task_obj | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user