diff --git a/joj3_config_generator/main.py b/joj3_config_generator/main.py index 91d879a..fb7b912 100644 --- a/joj3_config_generator/main.py +++ b/joj3_config_generator/main.py @@ -59,6 +59,7 @@ def convert( Convert given dir of JOJ3 toml config files to JOJ3 json config files """ logger.info(f"Converting files in {root.absolute()}") + root = root.absolute() for repo_toml_path in root.glob("**/repo.toml"): repo_path = repo_toml_path.parent repo_obj = rtoml.loads(repo_toml_path.read_text()) @@ -72,9 +73,9 @@ def convert( ) task_obj = rtoml.loads(task_toml_path.read_text()) 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.path = task_toml_path + task_conf.path = (root / task_toml_path.relative_to(root)).resolve() result_model = convert_conf(repo_conf, task_conf) result_dict = result_model.model_dump(by_alias=True, exclude_none=True) with result_json_path.open("w") as result_file: diff --git a/joj3_config_generator/processers/repo.py b/joj3_config_generator/processers/repo.py index 8d31e69..06b571f 100644 --- a/joj3_config_generator/processers/repo.py +++ b/joj3_config_generator/processers/repo.py @@ -111,7 +111,7 @@ def get_healthcheck_config(repo_conf: repo.Config) -> result.StageDetail: return healthcheck_stage -def calc_sha256sum(file_path: str) -> str: +def calc_sha256sum(file_path: Path) -> str: sha256_hash = hashlib.sha256() with open(file_path, "rb") as f: 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( immutable_files: list[str], repo_conf: repo.Config ) -> str: # input should be a list - # FIXME: should be finalized when get into the server - current_file_path = Path(__file__).resolve() - 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 + repo_path = repo_conf.path.parent + file_path = Path(f"{repo_path}/immutable_files") immutable_hash = [] + 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): - immutable_hash.append(calc_sha256sum(file)) + for i, file_ in enumerate(immutable_files_): + immutable_hash.append(calc_sha256sum(file_)) hash_check = "-checkFileSumList="