Merge pull request 'fixtures_flake: avoid fileinput' (#1889) from Mic92-blog/nixos-facter into main

This commit is contained in:
clan-bot
2024-08-14 15:05:56 +00:00

View File

@@ -1,4 +1,3 @@
import fileinput
import json import json
import logging import logging
import os import os
@@ -25,20 +24,23 @@ def substitute(
flake: Path = Path(__file__).parent, flake: Path = Path(__file__).parent,
) -> None: ) -> None:
sops_key = str(flake.joinpath("sops.key")) sops_key = str(flake.joinpath("sops.key"))
for line in fileinput.input(file, inplace=True): buf = ""
line = line.replace("__NIXPKGS__", str(nixpkgs_source())) with file.open() as f:
if clan_core_flake: for line in f:
line = line.replace("__CLAN_CORE__", str(clan_core_flake)) line = line.replace("__NIXPKGS__", str(nixpkgs_source()))
line = line.replace( if clan_core_flake:
"git+https://git.clan.lol/clan/clan-core", str(clan_core_flake) line = line.replace("__CLAN_CORE__", str(clan_core_flake))
) line = line.replace(
line = line.replace( "git+https://git.clan.lol/clan/clan-core", str(clan_core_flake)
"https://git.clan.lol/clan/clan-core/archive/main.tar.gz", )
str(clan_core_flake), line = line.replace(
) "https://git.clan.lol/clan/clan-core/archive/main.tar.gz",
line = line.replace("__CLAN_SOPS_KEY_PATH__", sops_key) str(clan_core_flake),
line = line.replace("__CLAN_SOPS_KEY_DIR__", str(flake)) )
print(line, end="") line = line.replace("__CLAN_SOPS_KEY_PATH__", sops_key)
line = line.replace("__CLAN_SOPS_KEY_DIR__", str(flake))
buf += line
file.write_text(buf)
class FlakeForTest(NamedTuple): class FlakeForTest(NamedTuple):
@@ -91,10 +93,13 @@ def generate_flake(
for file in flake.rglob("*"): for file in flake.rglob("*"):
if file.is_file(): if file.is_file():
print(f"Final Content of {file}:") print(f"Final Content of {file}:")
for line in fileinput.input(file, inplace=True): buf = ""
for key, value in substitutions.items(): with file.open() as f:
line = line.replace(key, value) for line in f:
print(line, end="") for key, value in substitutions.items():
line = line.replace(key, value)
buf += line
file.write_text(buf)
# generate machines from machineConfigs # generate machines from machineConfigs
for machine_name, machine_config in machine_configs.items(): for machine_name, machine_config in machine_configs.items():