automate: move working_dir to be set in constructor

This commit is contained in:
Iain Learmonth 2022-11-28 18:55:10 +00:00
parent efdaad977a
commit 109851745b
7 changed files with 59 additions and 43 deletions

View file

@ -43,10 +43,11 @@ class ListAutomation(TerraformAutomation):
in the templating of the Terraform configuration.
"""
def tf_generate(self, working_dir) -> None:
def tf_generate(self) -> None:
if not self.working_dir:
raise RuntimeError("No working directory specified.")
self.tf_write(
self.template,
working_dir,
lists=MirrorList.query.filter(
MirrorList.destroyed.is_(None),
MirrorList.provider == self.provider,
@ -66,9 +67,9 @@ class ListAutomation(TerraformAutomation):
for pool in Pool.query.filter(Pool.destroyed.is_(None)).all():
for key, formatter in lists.items():
for obfuscate in [True, False]:
with open(os.path.join(working_dir, f"{key}.{pool.pool_name}{'.jsno' if obfuscate else '.json'}"),
with open(os.path.join(self.working_dir, f"{key}.{pool.pool_name}{'.jsno' if obfuscate else '.json'}"),
'w', encoding="utf-8") as out:
out.write(json_encode(formatter(pool), obfuscate))
with open(os.path.join(working_dir, f"{key}.{pool.pool_name}{'.jso' if obfuscate else '.js'}"),
with open(os.path.join(self.working_dir, f"{key}.{pool.pool_name}{'.jso' if obfuscate else '.js'}"),
'w', encoding="utf-8") as out:
out.write(javascript_encode(formatter(pool), obfuscate))