From f4f75b85ead7cfd2eba672db7da3eb65b08c9810 Mon Sep 17 00:00:00 2001 From: Mc-muffin <8714476+Mc-muffin@users.noreply.github.com> Date: Wed, 6 Sep 2023 00:58:47 -0500 Subject: [PATCH] Add a feature to insert only changed files --- Tales_Exe.py | 9 ++++++++- pythonlib/games/ToolsTOR.py | 34 +++++++++++++++++++++++++++++++--- requirements.txt | 2 ++ 3 files changed, 41 insertions(+), 4 deletions(-) diff --git a/Tales_Exe.py b/Tales_Exe.py index 42c7c65..ac3ec47 100644 --- a/Tales_Exe.py +++ b/Tales_Exe.py @@ -184,6 +184,13 @@ def get_arguments(argv=None): default="", help="(Optional) - Insert lines in 'Problematic' status", ) + + sp_insert.add_argument( + "--only-changed", + required=False, + action="store_true", + help="(Optional) - Insert only changed files not yet commited", + ) # Debug commands sp_debug = sp.add_parser( @@ -259,7 +266,7 @@ def getTalesInstance(args, game_name): insert_mask = [args.with_proofreading, args.with_editing, args.with_problematic] else: insert_mask = [] - talesInstance = ToolsTOR.ToolsTOR(args.project.resolve(), insert_mask) + talesInstance = ToolsTOR.ToolsTOR(args.project.resolve(), insert_mask, args.only_changed) elif game_name == "NDX": talesInstance = ToolsNDX.ToolsNDX("TBL_All.json") else: diff --git a/pythonlib/games/ToolsTOR.py b/pythonlib/games/ToolsTOR.py index 7a1e25c..fb0ed40 100644 --- a/pythonlib/games/ToolsTOR.py +++ b/pythonlib/games/ToolsTOR.py @@ -24,6 +24,7 @@ from pythonlib.formats.theirsce_instructions import (AluOperation, InstructionTy TheirsceBaseInstruction) from .ToolsTales import ToolsTales import subprocess +from git import Repo @dataclass class LineEntry: @@ -47,7 +48,7 @@ class ToolsTOR(ToolsTales): LOW_BITS = 0x3F - def __init__(self, project_file: Path, insert_mask: list[str]) -> None: + def __init__(self, project_file: Path, insert_mask: list[str], changed_only: bool = False) -> None: base_path = project_file.parent self.jsonTblTags = {} self.ijsonTblTags = {} @@ -74,6 +75,9 @@ class ToolsTOR(ToolsTales): self.string_opcode = InstructionType.STRING self.list_status_insertion: list[str] = ['Done'] self.list_status_insertion.extend(insert_mask) + self.changed_only = changed_only + self.repo = Repo(base_path) + self.base_path = base_path # Extract the story files @@ -466,7 +470,19 @@ class ToolsTOR(ToolsTales): xml_path = self.paths["skit_xml"] pak2_path = self.paths["extracted_files"] / "DAT" / "PAK2" - for file in (pbar:= tqdm(list(pak2_path.glob("*.pak2")))): + in_list = [] + if self.changed_only: + for item in self.repo.index.diff(None): + item_path = Path(item.a_path) + if item_path.parent.name == "skits": + in_list.append(pak2_path / item_path.with_suffix(".3.pak2").name) + if len(in_list) == 0: + print("No changed files to insert...") + return + else: + in_list = list(pak2_path.glob("*.pak2")) + + for file in (pbar := tqdm(in_list)): pbar.set_description_str(file.name) with open(file, "rb") as f: pak2_data = f.read() @@ -920,7 +936,19 @@ class ToolsTOR(ToolsTales): xml_path = self.paths["story_xml"] scpk_path = self.paths["extracted_files"] / "DAT" / "SCPK" - for file in (pbar:= tqdm(list(scpk_path.glob("*.scpk")))): + in_list = [] + if self.changed_only: + for item in self.repo.index.diff(None): + item_path = Path(item.a_path) + if item_path.parent.name == "story": + in_list.append(scpk_path / item_path.with_suffix(".scpk").name) + if len(in_list) == 0: + print("No changed files to insert...") + return + else: + in_list = list(scpk_path.glob("*.scpk")) + + for file in (pbar:= tqdm(in_list)): pbar.set_description_str(file.name) curr_scpk = Scpk.from_path(file) old_rsce = Theirsce(curr_scpk.rsce) diff --git a/requirements.txt b/requirements.txt index d05e054..9c844d3 100644 --- a/requirements.txt +++ b/requirements.txt @@ -7,3 +7,5 @@ PyDrive==1.3.1 pygsheets==2.0.6 requests==2.30.0 tqdm==4.65.0 +pyjson5==1.6.3 +GitPython==3.1.34