fix: absolute path & immutable files feature
This commit is contained in:
		
							parent
							
								
									4adda6e716
								
							
						
					
					
						commit
						99ccbbd113
					
				|  | @ -59,6 +59,7 @@ def convert( | ||||||
|     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()}") | ||||||
|  |     root = root.absolute() | ||||||
|     for repo_toml_path in root.glob("**/repo.toml"): |     for repo_toml_path in root.glob("**/repo.toml"): | ||||||
|         repo_path = repo_toml_path.parent |         repo_path = repo_toml_path.parent | ||||||
|         repo_obj = rtoml.loads(repo_toml_path.read_text()) |         repo_obj = rtoml.loads(repo_toml_path.read_text()) | ||||||
|  | @ -72,9 +73,9 @@ def convert( | ||||||
|             ) |             ) | ||||||
|             task_obj = rtoml.loads(task_toml_path.read_text()) |             task_obj = rtoml.loads(task_toml_path.read_text()) | ||||||
|             repo_conf = repo.Config(**repo_obj) |             repo_conf = repo.Config(**repo_obj) | ||||||
|             repo_conf.path = repo_toml_path |             repo_conf.path = (root / repo_toml_path.relative_to(root)).resolve() | ||||||
|             task_conf = task.Config(**task_obj) |             task_conf = task.Config(**task_obj) | ||||||
|             task_conf.path = task_toml_path |             task_conf.path = (root / task_toml_path.relative_to(root)).resolve() | ||||||
|             result_model = convert_conf(repo_conf, task_conf) |             result_model = convert_conf(repo_conf, task_conf) | ||||||
|             result_dict = result_model.model_dump(by_alias=True, exclude_none=True) |             result_dict = result_model.model_dump(by_alias=True, exclude_none=True) | ||||||
|             with result_json_path.open("w") as result_file: |             with result_json_path.open("w") as result_file: | ||||||
|  |  | ||||||
|  | @ -111,7 +111,7 @@ def get_healthcheck_config(repo_conf: repo.Config) -> result.StageDetail: | ||||||
|     return healthcheck_stage |     return healthcheck_stage | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| def calc_sha256sum(file_path: str) -> str: | def calc_sha256sum(file_path: Path) -> str: | ||||||
|     sha256_hash = hashlib.sha256() |     sha256_hash = hashlib.sha256() | ||||||
|     with open(file_path, "rb") as f: |     with open(file_path, "rb") as f: | ||||||
|         for byte_block in iter(lambda: f.read(65536 * 2), b""): |         for byte_block in iter(lambda: f.read(65536 * 2), b""): | ||||||
|  | @ -122,20 +122,15 @@ def calc_sha256sum(file_path: str) -> str: | ||||||
| def get_hash( | def get_hash( | ||||||
|     immutable_files: list[str], repo_conf: repo.Config |     immutable_files: list[str], repo_conf: repo.Config | ||||||
| ) -> str:  # input should be a list | ) -> str:  # input should be a list | ||||||
|     # FIXME: should be finalized when get into the server |     repo_path = repo_conf.path.parent | ||||||
|     current_file_path = Path(__file__).resolve() |     file_path = Path(f"{repo_path}/immutable_files") | ||||||
|     project_root = current_file_path.parents[2] |  | ||||||
|     # FIXME: givin the path |  | ||||||
|     file_path = f"{project_root}/tests/immutable_file/" |  | ||||||
|     # file_path = "{Path.home()}/.cache/immutable" |  | ||||||
|     # to be use |  | ||||||
|     # file_path = repo_conf.path |  | ||||||
|     immutable_hash = [] |     immutable_hash = [] | ||||||
|  |     immutable_files_ = [] | ||||||
|     for i, file in enumerate(immutable_files): |     for i, file in enumerate(immutable_files): | ||||||
|         immutable_files[i] = file_path + file.rsplit("/", 1)[-1] |         immutable_files_.append(file_path.joinpath(file.rsplit("/", 1)[-1])) | ||||||
| 
 | 
 | ||||||
|     for i, file in enumerate(immutable_files): |     for i, file_ in enumerate(immutable_files_): | ||||||
|         immutable_hash.append(calc_sha256sum(file)) |         immutable_hash.append(calc_sha256sum(file_)) | ||||||
| 
 | 
 | ||||||
|     hash_check = "-checkFileSumList=" |     hash_check = "-checkFileSumList=" | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user