HOI4_randomchanges/dodo.py

80 lines
2.5 KiB
Python
Raw Normal View History

2023-11-11 16:37:22 +00:00
#!/usr/bin/env python3
from pathlib import Path
mod_name = 'randchgs'
mod_install_path = 'C:/Users/User/Documents/Paradox Interactive/Hearts of Iron IV/mod/randchgs'
vnla = "../vanilla"
dir_image = 'image'
dir_src_raw = 'src/raw'
class Patchwork(dict):
patches_path = "src/patches"
patchwork_path = "build/patched"
def prerequisites(self, vanilla_path):
for i in self.values():
yield f"{self.patches_path}/{i}"
for i in self.keys():
yield f"{vanilla_path}/{i}"
def targets(self):
for i in self.keys():
yield f"{self.patchwork_path}/{i}"
patchwork = Patchwork({
'map/definition.csv': 'map_definition.patch',
'history/countries/ISR - Israel.txt': 'history_countries_ISR.patch'
})
# def task_wipe():
# return {
# 'actions' :[f"rm -rf {dir_image} {patchwork.patchwork_path}"],
# 'uptodate': [True]
# }
def task_patch():
def acts():
for k, v in patchwork.items():
yield f"mkdir -p {patchwork.patchwork_path}/{Path(k).parent}"
yield f"patch -u --binary -N -o '{patchwork.patchwork_path}/{k}' "\
f"'{vnla}/{k}' '{patchwork.patches_path}/{v}'"
return {
'file_dep' : list(patchwork.prerequisites(vnla)),
'targets': list(patchwork.targets()),
'actions': list(acts())
}
def task_image():
def files(p):
for i in p:
if i.is_file():
yield i
filelist = list(files(Path(dir_src_raw).rglob("*"))) + \
list(files(Path(patchwork.patchwork_path).rglob("*")))
return {
'file_dep': filelist,
'targets': [f"{dir_image}/{mod_name}"],
'actions': [f"mkdir -p %(targets)s",
f"rsync -rv {dir_src_raw}/ {patchwork.patchwork_path}/"\
" %(targets)s/"]
}
def task_image_mod():
dep = 'src/raw/descriptor.mod'
def prepare_modname_mod(targets):
with open(dep) as s:
with open(targets[0], 'w') as o:
o.write(s.read())
o.write(f"path=\"{mod_install_path}\"")
return {
'file_dep': [dep],
'targets': [f"{dir_image}/{mod_name}.mod"],
'actions': [ prepare_modname_mod ]
}
def task_build():
return {
'task_dep' : ['image'],
'file_dep' : [f"image/{mod_name}.mod"],
'targets': [f"{dir_image}/{mod_name}.zip"],
'actions' : [f"cd {dir_image} && zip -r {mod_name}.zip {mod_name}",
f"cd {dir_image} && zip -r {mod_name}.zip {mod_name}.mod"]
}