mirror of
https://github.com/Faraphel/Atlas-Install.git
synced 2025-07-05 12:18:21 +02:00
Patch.safe_eval now have a env parameter where any variable can be used for the safe_eval
This commit is contained in:
parent
cb069fe240
commit
cb38bf3ae5
3 changed files with 8 additions and 8 deletions
|
@ -16,23 +16,23 @@ class Patch:
|
||||||
def __repr__(self) -> str:
|
def __repr__(self) -> str:
|
||||||
return f"<{self.__class__.__name__} {self.path}>"
|
return f"<{self.__class__.__name__} {self.path}>"
|
||||||
|
|
||||||
def safe_eval(self, template: str, extracted_game: "ExtractedGame") -> str:
|
def safe_eval(self, template: str, **env) -> str:
|
||||||
"""
|
"""
|
||||||
Safe eval with a patch environment
|
Safe eval with a patch environment
|
||||||
:param extracted_game: the extracted game to patch
|
:param env: other variable that are allowed in the safe_eval
|
||||||
:param template: template to evaluate
|
:param template: template to evaluate
|
||||||
:return: the result of the evaluation
|
:return: the result of the evaluation
|
||||||
"""
|
"""
|
||||||
return safe_eval(
|
return safe_eval(
|
||||||
template,
|
template,
|
||||||
extra_token_map={
|
extra_token_map={
|
||||||
"extracted_game": "extracted_game",
|
"extracted_game": "extracted_game"
|
||||||
"mod_config": "mod_config"
|
} | {
|
||||||
|
key: key for key in env
|
||||||
},
|
},
|
||||||
env={
|
env={
|
||||||
"extracted_game": extracted_game,
|
|
||||||
"mod_config": self.mod_config
|
"mod_config": self.mod_config
|
||||||
},
|
} | env,
|
||||||
)
|
)
|
||||||
|
|
||||||
def install(self, extracted_game: "ExtractedGame") -> Generator[dict, None, None]:
|
def install(self, extracted_game: "ExtractedGame") -> Generator[dict, None, None]:
|
||||||
|
|
|
@ -24,7 +24,7 @@ class PatchDirectory(PatchObject):
|
||||||
"""
|
"""
|
||||||
yield {"description": f"Patching {self}"}
|
yield {"description": f"Patching {self}"}
|
||||||
|
|
||||||
if self.patch.safe_eval(self.configuration["if"], extracted_game) == "False": return
|
if self.patch.safe_eval(self.configuration["if"], extracted_game=extracted_game) == "False": return
|
||||||
|
|
||||||
match self.configuration["mode"]:
|
match self.configuration["mode"]:
|
||||||
# if the mode is copy, then simply patch the subfile into the game with the same path
|
# if the mode is copy, then simply patch the subfile into the game with the same path
|
||||||
|
|
|
@ -31,7 +31,7 @@ class PatchFile(PatchObject):
|
||||||
yield {"description": f"Patching {self}"}
|
yield {"description": f"Patching {self}"}
|
||||||
|
|
||||||
# check if the file should be patched considering the "if" configuration
|
# check if the file should be patched considering the "if" configuration
|
||||||
if self.patch.safe_eval(self.configuration["if"], extracted_game) == "False": return
|
if self.patch.safe_eval(self.configuration["if"], extracted_game=extracted_game) == "False": return
|
||||||
|
|
||||||
# check if the path to the game_subpath is inside a szs, and if yes extract it
|
# check if the path to the game_subpath is inside a szs, and if yes extract it
|
||||||
for szs_subpath in filter(lambda path: path.suffix == ".d",
|
for szs_subpath in filter(lambda path: path.suffix == ".d",
|
||||||
|
|
Loading…
Reference in a new issue