23 lines
542 B
Python
23 lines
542 B
Python
import json
|
|
from pathlib import Path
|
|
from typing import Any
|
|
|
|
INFRA_STATE_FILE = ".qc-cli-infra.json"
|
|
|
|
|
|
def state_path(config_dir: str) -> Path:
|
|
return Path(config_dir) / INFRA_STATE_FILE
|
|
|
|
|
|
def read_infra_state(config_dir: str) -> dict[str, Any]:
|
|
path = state_path(config_dir)
|
|
if not path.exists():
|
|
return {}
|
|
with open(path) as f:
|
|
return json.load(f)
|
|
|
|
|
|
def write_infra_state(config_dir: str, state: dict[str, Any]) -> None:
|
|
with open(state_path(config_dir), "w") as f:
|
|
json.dump(state, f, indent=2)
|