mirror of
https://github.com/FAUSheppy/homelab_gamevault
synced 2025-12-06 15:01:36 +01:00
feat: support for jinja templates reg files
This commit is contained in:
Binary file not shown.
Binary file not shown.
31
jinja_helper.py
Normal file
31
jinja_helper.py
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
import jinja2
|
||||||
|
import os
|
||||||
|
|
||||||
|
def render_path(path, install_location, game_directory):
|
||||||
|
|
||||||
|
# sanity check input path #
|
||||||
|
if not path.endswith(".reg.j2"):
|
||||||
|
raise NotImplementedError("Path must end in .reg.j2 for Jinja-Module")
|
||||||
|
|
||||||
|
# build result path #
|
||||||
|
result_path = path[:-len(".j2")]
|
||||||
|
|
||||||
|
# prepare template #
|
||||||
|
input_content = ""
|
||||||
|
with open(path, encoding="utf-16") as f:
|
||||||
|
input_content = f.read()
|
||||||
|
|
||||||
|
template = jinja2.Template(input_content)
|
||||||
|
print("in", input_content)
|
||||||
|
# render #
|
||||||
|
output_content = template.render(
|
||||||
|
install_dir=os.path.join(install_location, game_directory).replace("\\", "\\\\"),
|
||||||
|
user_home=os.path.expanduser("~").replace("\\", "\\\\")
|
||||||
|
)
|
||||||
|
|
||||||
|
# save new file #
|
||||||
|
with open(result_path, "w", encoding="utf-16") as f:
|
||||||
|
f.write(output_content)
|
||||||
|
|
||||||
|
print(output_content)
|
||||||
|
return result_path
|
||||||
@@ -6,6 +6,7 @@ import shutil
|
|||||||
import pathlib
|
import pathlib
|
||||||
import tqdm
|
import tqdm
|
||||||
import webbrowser
|
import webbrowser
|
||||||
|
import jinja_helper
|
||||||
|
|
||||||
class Software:
|
class Software:
|
||||||
|
|
||||||
@@ -107,6 +108,9 @@ class Software:
|
|||||||
# download & install registry files #
|
# download & install registry files #
|
||||||
for rf in self.reg_files:
|
for rf in self.reg_files:
|
||||||
path = self.backend.get(rf, cache_dir=self.cache_dir)
|
path = self.backend.get(rf, cache_dir=self.cache_dir)
|
||||||
|
if path.endswith(".j2"):
|
||||||
|
path = jinja_helper.render_path(path, self.backend.install_dir, self.directory)
|
||||||
|
|
||||||
localaction.install_registry_file(path)
|
localaction.install_registry_file(path)
|
||||||
|
|
||||||
# install dependencies #
|
# install dependencies #
|
||||||
|
|||||||
Reference in New Issue
Block a user