ADD paths module

To automate the fetching of the state file in a safe, atomic way.
This commit is contained in:
2025-12-17 23:49:50 +00:00
parent 8f07c9a247
commit 35a68b04a8

20
rewind/paths.py Normal file
View File

@@ -0,0 +1,20 @@
from pathlib import Path
import os, json
APP_NAME = "rewind"
def state_dir() -> Path:
base = os.path.expanduser("~/.local/share")
path = Path(base) / APP_NAME
path.mkdir(parents=True, exist_ok=True)
return 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():
return {"files": []}
with path.open() as f:
return json.load(f)