From 4e5033b7b9e707372f758b8cdf7e6a78cd30819b Mon Sep 17 00:00:00 2001 From: Hiroshiba Date: Fri, 15 Nov 2024 13:05:28 +0900 Subject: [PATCH 1/2] merge-engine-manifest.py --- tools/merge_engine_manifest.py | 49 ++++++++++++++++++++++++++++++++++ tools/merge_update_infos.py | 4 +-- 2 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 tools/merge_engine_manifest.py diff --git a/tools/merge_engine_manifest.py b/tools/merge_engine_manifest.py new file mode 100644 index 000000000..d90f846d8 --- /dev/null +++ b/tools/merge_engine_manifest.py @@ -0,0 +1,49 @@ +""" +エンジンマニフェストをマージする。 +""" + +import argparse +import json +from pathlib import Path + +JsonValue = str | int | float + + +def merge_json_string(src: str, dst: str) -> str: + src_json: dict[str, JsonValue | dict[str, dict]] = json.loads(src) + dst_json: dict[str, JsonValue | dict[str, dict]] = json.loads(dst) + + for key, dst_value in dst_json.items(): + assert key in src_json, f"Key {key} is not found in src_json" + + # `manage_library` のみdictなので特別に処理 + if key == "supported_features": + assert isinstance(dst_value, dict) + + src_value = src_json[key] + assert isinstance(src_value, dict) + src_value.update(dst_value) + + else: + src_value = src_json[key] + assert isinstance(src_value, JsonValue) + assert isinstance(dst_value, JsonValue) + src_json[key] = dst_value + + return json.dumps(src_json, ensure_ascii=False) + + +def merge_engine_manifest(src_path: Path, dst_path: Path, output_path: Path) -> None: + src = src_path.read_text(encoding="utf-8") + dst = dst_path.read_text(encoding="utf-8") + merged = merge_json_string(src, dst) + output_path.write_text(merged, encoding="utf-8") + + +if __name__ == "__main__": + parser = argparse.ArgumentParser() + parser.add_argument("src_path", type=Path) + parser.add_argument("dst_path", type=Path) + parser.add_argument("output_path", type=Path) + args = parser.parse_args() + merge_engine_manifest(args.src_path, args.dst_path, args.output_path) diff --git a/tools/merge_update_infos.py b/tools/merge_update_infos.py index 7c1ea5784..8ae08cb27 100644 --- a/tools/merge_update_infos.py +++ b/tools/merge_update_infos.py @@ -42,14 +42,14 @@ def merge_json_string(src: str, dst: str) -> str: # 異なるものがあった場合だけ後ろに付け足す src_item[key] = list(OrderedDict.fromkeys(src_value + dst_value)) - return json.dumps(src_json) + return json.dumps(src_json, ensure_ascii=False) def merge_update_infos(src_path: Path, dst_path: Path, output_path: Path) -> None: src = src_path.read_text(encoding="utf-8") dst = dst_path.read_text(encoding="utf-8") merged = merge_json_string(src, dst) - output_path.write_text(merged) + output_path.write_text(merged, encoding="utf-8") if __name__ == "__main__": From bcb480a7660d9af8b0e36fa4d036ce4f01a7a561 Mon Sep 17 00:00:00 2001 From: Hiroshiba Date: Fri, 15 Nov 2024 13:08:21 +0900 Subject: [PATCH 2/2] =?UTF-8?q?refactor:=20=E3=82=A8=E3=83=B3=E3=82=B8?= =?UTF-8?q?=E3=83=B3=E3=83=9E=E3=83=8B=E3=83=95=E3=82=A7=E3=82=B9=E3=83=88?= =?UTF-8?q?=E3=81=AE=E7=B5=B1=E5=90=88=E5=87=A6=E7=90=86=E3=82=92=E6=94=B9?= =?UTF-8?q?=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tools/process_voicevox_resource.bash | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tools/process_voicevox_resource.bash b/tools/process_voicevox_resource.bash index 086557209..acdc32ae8 100644 --- a/tools/process_voicevox_resource.bash +++ b/tools/process_voicevox_resource.bash @@ -13,10 +13,11 @@ cp -r "${DOWNLOAD_RESOURCE_PATH}/character_info" resources/character_info python "${DOWNLOAD_RESOURCE_PATH}/scripts/clean_character_info.py" \ --character_info_dir resources/character_info/ -# エンジンマニフェストに含まれるダミーの情報を上書きする -jq -s '.[0] * .[1]' engine_manifest.json "${DOWNLOAD_RESOURCE_PATH}/engine/engine_manifest.json" \ - > engine_manifest.json.tmp -mv engine_manifest.json.tmp engine_manifest.json +# エンジンマニフェストを統合する +python tools/merge_engine_manifest.py \ + engine_manifest.json \ + "${DOWNLOAD_RESOURCE_PATH}/engine/engine_manifest.json" \ + engine_manifest.json # エンジンとリソースの更新情報を統合する python tools/merge_update_infos.py \