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 | 5c76a1257b4a058bf919af3e31cc9461a39c2f33 (patch) | |
tree | cb32f0c22e5438a0ed9de4b29f58d0b7f142a58d /tools/cru-py/cru/template.py | |
parent | 12e1272508ba0b5909069319007d677c1c76e355 (diff) | |
download | crupest-5c76a1257b4a058bf919af3e31cc9461a39c2f33.tar.gz crupest-5c76a1257b4a058bf919af3e31cc9461a39c2f33.tar.bz2 crupest-5c76a1257b4a058bf919af3e31cc9461a39c2f33.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) |