MOVE write_state and load_state functions to paths.py
This is to encapsulate all path and state file related operations within the paths module.
This commit is contained in:
@@ -12,9 +12,14 @@ def state_dir() -> Path:
|
||||
def get_state_file_path() -> Path:
|
||||
return state_dir() / "state.json"
|
||||
|
||||
def get_state_file() -> dict:
|
||||
path = get_state_file_path()
|
||||
if not path.exists():
|
||||
def load_state() -> dict:
|
||||
if not get_state_file_path.exists():
|
||||
return {"files": []}
|
||||
with path.open() as f:
|
||||
return json.load(f)
|
||||
with get_state_file_path.open() as f:
|
||||
return json.load(f)
|
||||
|
||||
def write_state(state: dict):
|
||||
tmp = get_state_file_path().with_suffix(".tmp")
|
||||
with tmp.open("w") as f:
|
||||
json.dump(state, f, indent=2)
|
||||
tmp.replace(get_state_file_path()) # atomic
|
||||
|
||||
Reference in New Issue
Block a user