Files
hy3d/hy3d/config.py
T
KawasakiAkasei 3e85d6f987 refactor: move config dir to ~/.config/hy3d, replace skill with run-hy3d
- config dir renamed hunyuan3dweb -> hy3d (cookies/profile moved intact,
  auth re-verified: quota 20/20)
- cli.py/login.py/READMEs/doc paths updated to ~/.config/hy3d
- skill: delete run-hunyuan3dweb, add run-hy3d pointing at bin/hy3d
- zero stale old-name references remain (one historical note in skill)
2026-08-15 22:44:56 +08:00

45 lines
1.3 KiB
Python

import os
import shutil
import tempfile
from pathlib import Path
from typing import Optional, Tuple
def get_config_dir() -> Path:
"""Return the user configuration directory (~/.config/hy3d)."""
xdg = os.environ.get("XDG_CONFIG_HOME")
base = Path(xdg) if xdg else Path.home() / ".config"
path = base / "hy3d"
path.mkdir(parents=True, exist_ok=True)
return path
def get_cookie_path() -> Path:
"""Return the path to the cookies file."""
return get_config_dir() / "cookies.txt"
def get_profile_dir() -> Path:
"""Return the path to the browser profile directory."""
path = get_config_dir() / "profile"
path.mkdir(parents=True, exist_ok=True)
return path
def prepare_profile_dir() -> Tuple[str, Optional[str]]:
"""
将标准 profile 复制到临时目录,避免 Chromium 锁冲突。
Returns:
(实际使用的 profile 路径, 临时目录路径或 None)。
如果使用了临时副本,调用者应在完成后用 shutil.rmtree 删除。
"""
standard = str(get_profile_dir())
if not os.path.exists(standard):
return standard, None
temp_root = tempfile.mkdtemp(prefix="hy3d-profile-")
temp_profile = os.path.join(temp_root, "profile")
shutil.copytree(standard, temp_profile, dirs_exist_ok=True)
return temp_profile, temp_root