Files
CSG-Picker-Shipper-Helper/app/paths.py
T
2026-07-06 00:24:30 -05:00

46 lines
1.3 KiB
Python

"""Canonical per-user data paths for the application.
All persistent artifacts (SQLite DB, image cache, label PDFs, history JSON,
package presets, log file) live under one directory so they're easy to find,
back up, or nuke without touching the install.
"""
from __future__ import annotations
import os
from pathlib import Path
_APP_SUBDIR = Path("CollisionStoneGuard") / "PartsLookup"
def appdata_dir() -> Path:
"""Return (and create) the per-user appdata directory.
Resolution order:
1. %LOCALAPPDATA% (Windows standard)
2. ~/AppData/Local (fallback — same folder, explicit)
3. ~ (last resort)
"""
local = os.environ.get("LOCALAPPDATA", "")
base = Path(local) if local else Path.home() / "AppData" / "Local"
d = base / _APP_SUBDIR
d.mkdir(parents=True, exist_ok=True)
return d
def default_sqlite_path() -> str:
"""Default path for the parts/invoices SQLite database."""
return str(appdata_dir() / "parts.db")
def default_image_cache_dir() -> str:
"""Default directory for cached part images."""
p = appdata_dir() / "images"
p.mkdir(exist_ok=True)
return str(p)
def log_file_path() -> Path:
"""Path for the application log file."""
return appdata_dir() / "app.log"