mirror of
https://github.com/basnijholt/compose-farm.git
synced 2026-08-02 03:11:30 +01:00
* refactor(web): store backups in XDG config directory Move file backups from `.backups/` alongside the file to `~/.config/compose-farm/backups/` (respecting XDG_CONFIG_HOME). The original file path is mirrored inside to avoid name collisions. * docs(web): document automatic backup location * refactor(paths): extract shared config_dir() function * fix(web): use path anchor for Windows compatibility
44 lines
1.2 KiB
Python
44 lines
1.2 KiB
Python
"""Path utilities - lightweight module with no heavy dependencies."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import os
|
|
from pathlib import Path
|
|
|
|
|
|
def xdg_config_home() -> Path:
|
|
"""Get XDG config directory, respecting XDG_CONFIG_HOME env var."""
|
|
return Path(os.environ.get("XDG_CONFIG_HOME", Path.home() / ".config"))
|
|
|
|
|
|
def config_dir() -> Path:
|
|
"""Get the compose-farm config directory."""
|
|
return xdg_config_home() / "compose-farm"
|
|
|
|
|
|
def default_config_path() -> Path:
|
|
"""Get the default user config path."""
|
|
return config_dir() / "compose-farm.yaml"
|
|
|
|
|
|
def backup_dir() -> Path:
|
|
"""Get the backup directory for file edits."""
|
|
return config_dir() / "backups"
|
|
|
|
|
|
def config_search_paths() -> list[Path]:
|
|
"""Get search paths for config files."""
|
|
return [Path("compose-farm.yaml"), default_config_path()]
|
|
|
|
|
|
def find_config_path() -> Path | None:
|
|
"""Find the config file path, checking CF_CONFIG env var and search paths."""
|
|
if env_path := os.environ.get("CF_CONFIG"):
|
|
p = Path(env_path)
|
|
if p.exists() and p.is_file():
|
|
return p
|
|
for p in config_search_paths():
|
|
if p.exists() and p.is_file():
|
|
return p
|
|
return None
|