diff options
author | crupest <crupest@outlook.com> | 2024-11-11 01:12:29 +0800 |
---|---|---|
committer | Yuqian Yang <crupest@crupest.life> | 2025-01-20 22:34:18 +0800 |
commit | 103adca3b574fddc697d9daf4a0807bf42e972b5 (patch) | |
tree | cb32f0c22e5438a0ed9de4b29f58d0b7f142a58d /tools/cru-py/cru/template.py | |
parent | beb655553bf6ec4b403bfe44c1e20073342285e0 (diff) | |
download | crupest-103adca3b574fddc697d9daf4a0807bf42e972b5.tar.gz crupest-103adca3b574fddc697d9daf4a0807bf42e972b5.tar.bz2 crupest-103adca3b574fddc697d9daf4a0807bf42e972b5.zip |
HALF WORK: 2024.1.20 - 2
Diffstat (limited to 'tools/cru-py/cru/template.py')
-rw-r--r-- | tools/cru-py/cru/template.py | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/tools/cru-py/cru/template.py b/tools/cru-py/cru/template.py index 2b0f1bc..74a5c9a 100644 --- a/tools/cru-py/cru/template.py +++ b/tools/cru-py/cru/template.py @@ -137,7 +137,13 @@ class TemplateTree: s.update(template.variables) return s - def generate_to(self, destination: str, variables: Mapping[str, str]) -> None: + def generate_to( + self, destination: str, variables: Mapping[str, str], dry_run: bool + ) -> None: for file, template in self.templates: - with open(os.path.join(destination, file), "w") as f: - f.write(template.generate(variables)) + des = CruPath(destination) / file + text = template.generate(variables) + if not dry_run: + des.parent.mkdir(parents=True, exist_ok=True) + with open(des, "w") as f: + f.write(text) |