fixtures_flake: avoid fileinput
it seems that the inplace argument in some cases picks up output from unrelated functions. Since the file is relativly small, we can just replace the content in one go.
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
import fileinput
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
@@ -25,7 +24,9 @@ def substitute(
|
||||
flake: Path = Path(__file__).parent,
|
||||
) -> None:
|
||||
sops_key = str(flake.joinpath("sops.key"))
|
||||
for line in fileinput.input(file, inplace=True):
|
||||
buf = ""
|
||||
with file.open() as f:
|
||||
for line in f:
|
||||
line = line.replace("__NIXPKGS__", str(nixpkgs_source()))
|
||||
if clan_core_flake:
|
||||
line = line.replace("__CLAN_CORE__", str(clan_core_flake))
|
||||
@@ -38,7 +39,8 @@ def substitute(
|
||||
)
|
||||
line = line.replace("__CLAN_SOPS_KEY_PATH__", sops_key)
|
||||
line = line.replace("__CLAN_SOPS_KEY_DIR__", str(flake))
|
||||
print(line, end="")
|
||||
buf += line
|
||||
file.write_text(buf)
|
||||
|
||||
|
||||
class FlakeForTest(NamedTuple):
|
||||
@@ -91,10 +93,13 @@ def generate_flake(
|
||||
for file in flake.rglob("*"):
|
||||
if file.is_file():
|
||||
print(f"Final Content of {file}:")
|
||||
for line in fileinput.input(file, inplace=True):
|
||||
buf = ""
|
||||
with file.open() as f:
|
||||
for line in f:
|
||||
for key, value in substitutions.items():
|
||||
line = line.replace(key, value)
|
||||
print(line, end="")
|
||||
buf += line
|
||||
file.write_text(buf)
|
||||
|
||||
# generate machines from machineConfigs
|
||||
for machine_name, machine_config in machine_configs.items():
|
||||
|
||||
Reference in New Issue
Block a user