27 lines
603 B
Python
27 lines
603 B
Python
from __future__ import annotations
|
|
|
|
import os
|
|
from pathlib import Path
|
|
|
|
|
|
APP_DIR_NAME = "BakRest"
|
|
CONFIG_ENV_VAR = "BAKREST_CONFIG"
|
|
|
|
|
|
def program_data_dir() -> Path:
|
|
base = os.environ.get("PROGRAMDATA")
|
|
if base:
|
|
return Path(base) / APP_DIR_NAME
|
|
return Path.home() / f".{APP_DIR_NAME.lower()}"
|
|
|
|
|
|
def default_config_path() -> Path:
|
|
configured = os.environ.get(CONFIG_ENV_VAR)
|
|
if configured:
|
|
return Path(configured).expanduser()
|
|
return program_data_dir() / "config.toml"
|
|
|
|
|
|
def expand_path(value: str) -> Path:
|
|
return Path(os.path.expandvars(value)).expanduser()
|