diff --git a/dodo.py b/dodo.py index 88423f9..476271f 100644 --- a/dodo.py +++ b/dodo.py @@ -16,21 +16,9 @@ class Patchwork(dict): self.patchwork_path = Path(kwargs.pop("patchwork_path")) super().__init__(*arkg, **kwargs) patchwork_mkdir = 'mkdir -p {}/{}' - def prerequisites(self, vanilla_path): - for i in self.values(): - yield self.patches_path/i - for i in self.keys(): - yield vanilla_path/i def targets(self): for i in self.keys(): yield self.patchwork_path/i - def action_generator(self, key, value, vanilla_path): - yield f"mkdir -p {self.patchwork_path}/{Path(key).parent}" - yield f"patch -u --binary -N -o '{self.patchwork_path}/{key}' "\ - f"'{vanilla_path}/{key}' '{self.patches_path}/{value}'" - def actions(self, vanilla_path): - for k, v in self.items(): - yield from self.action_generator(k, v, vanilla_path) def tasks(self, vanilla_path): for k, v in self.items(): yield ( @@ -44,6 +32,12 @@ class Patchwork(dict): ) +class ScriptedPatchwork(dict): + def __init__(self, source_file): + with open(source_file) as s: + super().__init__(safe_load(s)) + + mod_name = 'randchgs' mod_install_path = 'C:/Users/User/Documents/Paradox Interactive/Hearts of Iron IV/mod/randchgs' dir_vanilla = Path("../vanilla/v1.13.4") @@ -53,14 +47,16 @@ dir_src_raw = Path('src/raw') dir_src_raw_files = list(files(Path(dir_src_raw).rglob("*"))) dir_patches_path = Path('src/patches') dir_patchwork_path = Path('build/patched') + patchwork = Patchwork({ 'map/definition.csv': 'map_definition.patch', 'history/countries/ISR - Israel.txt': 'history_countries_ISR.patch', - # 'history/states/728-Guangzhouwan.txt' : 'history_states_728.patch', -}, patches_path = dir_patches_path, patchwork_path = dir_patchwork_path ) -patchwork_scripted_template_input_file = dir_patches_path/'extrapoint.yaml' -with open(patchwork_scripted_template_input_file) as s: - patchwork_scripted_template_input_data = safe_load(s) +}, + patches_path = dir_patches_path, + patchwork_path = dir_patchwork_path +) + +patchwork_scripted = ScriptedPatchwork(dir_patches_path/'extrapoint.yaml') dir_image_files = [ f"{dir_modimage}/{f.relative_to(dir_src_raw)}" for f in dir_src_raw_files ] + \ [ f"{dir_modimage}/{f.relative_to(patchwork.patchwork_path)}" for f in patchwork.targets() ] @@ -92,13 +88,12 @@ def task_patch_history_states_scripted(): if not wrote_history and seen_history and '{' in line_in: for province_id, province_info in provinces.items(): outfile.write( - "\t\tvictory_points = {\n"\ - f"\t\t\t{province_id} {province_info['points']}\n"\ - "\t\t}\n"\ + "\t\tvictory_points = {\r\n"\ + f"\t\t\t{province_id} {province_info['points']}\r\n"\ + "\t\t}\r\n"\ ) wrote_history = True - target.touch() - for state_id, state_data in patchwork_scripted_template_input_data.items(): + for state_id, state_data in patchwork_scripted.items(): files = history_states_path(state_id) yield { 'name' : f"{state_id}", @@ -124,7 +119,7 @@ def task_image(): return { 'file_dep' : filelist + [ history_states_path(state_id)['dest'] - for state_id in patchwork_scripted_template_input_data.keys() ], + for state_id in patchwork_scripted.keys() ], 'targets' : dir_image_files, 'actions' : [f"mkdir -p {dir_modimage}", f"rsync -rv {dir_src_raw}/ {patchwork.patchwork_path}/"\