refactor(state): move state directory function into paths module
This commit is contained in:
@@ -6,7 +6,6 @@ from importlib import resources
|
|||||||
|
|
||||||
APP_NAME = "rewind"
|
APP_NAME = "rewind"
|
||||||
CONFIG_NAME = "config.toml"
|
CONFIG_NAME = "config.toml"
|
||||||
STATE_NAME = "state.json"
|
|
||||||
|
|
||||||
def get_config_dir() -> Path:
|
def get_config_dir() -> Path:
|
||||||
base = os.environ.get("XDG_CONFIG_HOME", Path.home() / ".config")
|
base = os.environ.get("XDG_CONFIG_HOME", Path.home() / ".config")
|
||||||
@@ -25,4 +24,9 @@ def load_config() -> dict:
|
|||||||
|
|
||||||
with config_file.open("rb") as f:
|
with config_file.open("rb") as f:
|
||||||
return tomllib.load(f)
|
return tomllib.load(f)
|
||||||
|
|
||||||
|
def get_state_dir() -> Path:
|
||||||
|
base = os.path.expanduser("~/.local/share")
|
||||||
|
path = Path(base) / APP_NAME
|
||||||
|
path.mkdir(parents=True, exist_ok=True)
|
||||||
|
return path
|
||||||
@@ -4,18 +4,12 @@ import json
|
|||||||
import os
|
import os
|
||||||
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
from rewind.paths import get_state_dir
|
||||||
|
|
||||||
APP_NAME = "rewind"
|
|
||||||
STATE_NAME = "state.json"
|
STATE_NAME = "state.json"
|
||||||
|
|
||||||
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:
|
def get_state_file_path() -> Path:
|
||||||
return state_dir() / STATE_NAME
|
return get_state_dir() / STATE_NAME
|
||||||
|
|
||||||
def load_state() -> dict:
|
def load_state() -> dict:
|
||||||
if not get_state_file_path().exists():
|
if not get_state_file_path().exists():
|
||||||
|
|||||||
Reference in New Issue
Block a user