refactor(lib/persist): move WriteInfo class into persistence lib
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import json
|
||||
from dataclasses import dataclass
|
||||
|
||||
from clan_cli.errors import ClanError
|
||||
from clan_cli.flake import Flake
|
||||
@@ -7,7 +8,6 @@ from clan_cli.git import commit_file
|
||||
from clan_lib.nix_models.inventory import Inventory
|
||||
|
||||
from .util import (
|
||||
WriteInfo,
|
||||
calc_patches,
|
||||
delete_by_path,
|
||||
determine_writeability,
|
||||
@@ -15,6 +15,13 @@ from .util import (
|
||||
)
|
||||
|
||||
|
||||
@dataclass
|
||||
class WriteInfo:
|
||||
writeables: dict[str, set[str]]
|
||||
data_eval: Inventory
|
||||
data_disk: Inventory
|
||||
|
||||
|
||||
class InventoryStore:
|
||||
def __init__(
|
||||
self,
|
||||
|
||||
@@ -1,25 +1,13 @@
|
||||
"""
|
||||
All read/write operations MUST use the inventory.
|
||||
|
||||
Machine data, clan data or service data can be accessed in a performant way.
|
||||
|
||||
This file exports stable classnames for static & dynamic type safety.
|
||||
|
||||
Utilize:
|
||||
|
||||
- load_inventory_eval: To load the actual inventory with nix declarations merged.
|
||||
Operate on the returned inventory to make changes
|
||||
- save_inventory: To persist changes.
|
||||
Utilities for working with nested dictionaries, particularly for
|
||||
flattening, unmerging lists, finding duplicates, and calculating patches.
|
||||
"""
|
||||
|
||||
from collections import Counter
|
||||
from dataclasses import dataclass
|
||||
from typing import Any
|
||||
|
||||
from clan_cli.errors import ClanError
|
||||
|
||||
from clan_lib.nix_models.inventory import Inventory
|
||||
|
||||
|
||||
def flatten_data(data: dict, parent_key: str = "", separator: str = ".") -> dict:
|
||||
"""
|
||||
@@ -334,10 +322,3 @@ def patch(d: dict[str, Any], path: str, content: Any) -> None:
|
||||
for key in keys[:-1]:
|
||||
current = current.setdefault(key, {})
|
||||
current[keys[-1]] = content
|
||||
|
||||
|
||||
@dataclass
|
||||
class WriteInfo:
|
||||
writeables: dict[str, set[str]]
|
||||
data_eval: Inventory
|
||||
data_disk: Inventory
|
||||
|
||||
Reference in New Issue
Block a user