Use platformdirs for config and log locations

Config and logs now live in local (non-roaming) app data on Windows
(%LOCALAPPDATA%\mediahive) instead of roaming. Existing files in the
old roaming location are left untouched; no migration.
This commit is contained in:
2026-09-23 00:44:10 +00:00
parent f9002b19a2
commit 50420984f1
2 changed files with 16 additions and 13 deletions
+15 -13
View File
@@ -1,17 +1,19 @@
r"""Platform-appropriate config persistence for MediaHive.
Config file location:
Windows: %APPDATA%\mediahive\config.toml
macOS: ~/Library/Application Support/mediahive/config.toml
Linux: $XDG_CONFIG_HOME/mediahive/config.toml (~/.config/mediahive/config.toml)
Locations (via platformdirs):
Config — Windows: %LOCALAPPDATA%\mediahive\config.toml
macOS: ~/Library/Application Support/mediahive/config.toml
Linux: $XDG_CONFIG_HOME/mediahive/config.toml
Logs — Windows: %LOCALAPPDATA%\mediahive\mediahive.log
macOS: ~/Library/Logs/mediahive/mediahive.log
Linux: $XDG_STATE_HOME/mediahive/mediahive.log
"""
import os
import sys
from pathlib import Path
import msgspec
import msgspec.toml
from platformdirs import user_config_path, user_log_path
class Config(msgspec.Struct, omit_defaults=True):
@@ -20,13 +22,13 @@ class Config(msgspec.Struct, omit_defaults=True):
def config_dir() -> Path:
if sys.platform == "win32":
base = Path(os.environ.get("APPDATA") or Path.home())
elif sys.platform == "darwin":
base = Path.home() / "Library" / "Application Support"
else:
base = Path(os.environ.get("XDG_CONFIG_HOME") or (Path.home() / ".config"))
return base / "mediahive"
# Local (non-roaming) on Windows: config is machine-specific state,
# not something to sync across a domain profile.
return user_config_path("mediahive", roaming=False)
def log_dir() -> Path:
return user_log_path("mediahive", opinion=False)
def config_path() -> Path:
+1
View File
@@ -13,6 +13,7 @@ dependencies = [
"httpx[http2]>=0.28.1",
"msgspec>=0.19",
"parse-torrent-title>=2.8.1",
"platformdirs>=4.0",
"tomli-w>=1.2.0",
"uvicorn[standard]>=0.40.0",
]