Files
BiliNote/backend/app/utils/path_helper.py
黄建武 0a5196a475 refactor(utils): 更新模型目录获取逻辑以支持打包运行
-增加对打包状态的判断,使用不同的目录路径
-打包时将模型目录设置为 APPDATA 或 ~/.cache 下的 BiliNote/models
- 开发时仍使用项目根目录下的 models目录
- 确保兼容性和可移植性
2025-05-09 10:27:16 +08:00

27 lines
801 B
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import os
import sys
from pathlib import Path
PROJECT_ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), "../../"))
def get_data_dir():
data_path = os.path.join(PROJECT_ROOT, "data")
os.makedirs(data_path, exist_ok=True)
return data_path
def get_model_dir(subdir: str = "whisper") -> str:
# 判断是否为打包状态PyInstaller
if getattr(sys, 'frozen', False):
# exe 执行,放在 APPDATA 或 ~/.cache 下
base_dir = os.path.join(os.getenv("APPDATA") or str(Path.home()), "BiliNote", "models")
else:
# 开发时,相对项目根目录
base_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), "../../models"))
path = os.path.join(base_dir, subdir)
os.makedirs(path, exist_ok=True)
return path