Inventory: automatically create emtpy file on write
This commit is contained in:
committed by
hsjobeki
parent
dee284d669
commit
9b706c148b
@@ -473,8 +473,16 @@ def patch(d: dict[str, Any], path: str, content: Any) -> None:
|
||||
|
||||
@API.register
|
||||
def patch_inventory_with(base_dir: Path, section: str, content: dict[str, Any]) -> None:
|
||||
"""
|
||||
Pass only the section to update and the content to update with.
|
||||
Make sure you pass only attributes that you would like to persist.
|
||||
ATTENTION: Don't pass nix eval values unintentionally.
|
||||
"""
|
||||
|
||||
inventory_file = get_inventory_path(base_dir)
|
||||
|
||||
curr_inventory = {}
|
||||
if inventory_file.exists():
|
||||
with inventory_file.open("r") as f:
|
||||
curr_inventory = json.load(f)
|
||||
|
||||
|
||||
@@ -12,12 +12,11 @@ from clan_cli.flake import Flake
|
||||
from clan_cli.git import commit_file
|
||||
from clan_cli.inventory import (
|
||||
Machine as InventoryMachine,
|
||||
patch_inventory_with,
|
||||
dataclass_to_dict,
|
||||
)
|
||||
from clan_cli.inventory import (
|
||||
MachineDeploy,
|
||||
get_inventory,
|
||||
dataclass_to_dict,
|
||||
patch_inventory_with,
|
||||
)
|
||||
from clan_cli.machines.list import list_nixos_machines
|
||||
from clan_cli.templates import (
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
# Functions to test
|
||||
from typing import Any
|
||||
|
||||
import pytest
|
||||
from clan_cli.errors import ClanError
|
||||
from clan_cli.inventory import (
|
||||
@@ -370,7 +372,7 @@ def test_dont_persist_defaults() -> None:
|
||||
"enabled": True,
|
||||
"config": {"foo": "bar"},
|
||||
}
|
||||
data_disk = {}
|
||||
data_disk: dict[str, Any] = {}
|
||||
writeables = determine_writeability(prios, data_eval, data_disk)
|
||||
assert writeables == {"writeable": {"config", "enabled"}, "non_writeable": set()}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user