iOSBuildServer/backend/config.py
shen 6f4f625c56 Initial commit: iOS Build Server
- FastAPI backend with build queue, WebSocket logs, task management
- Vue 3 frontend with build/config/history views
- Xcode project build automation with IPA export
- Fix: initialize build_dir before try block to ensure cleanup on early failure
2026-06-06 17:42:27 +08:00

68 lines
2.1 KiB
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.

"""项目配置 — 从环境变量读取,支持 .env 文件"""
import os
from pathlib import Path
# 自动加载 .env 文件(如果存在)
_env_file = Path(__file__).parent.parent / ".env"
if _env_file.exists():
with open(_env_file) as f:
for line in f:
line = line.strip()
if line and not line.startswith("#") and "=" in line:
key, _, value = line.partition("=")
os.environ.setdefault(key.strip(), value.strip())
# 项目根目录iOS 源码,也作为 AutoPacking 脚本来源)
PROJECT_ROOT = Path(os.getenv("PROJECT_ROOT", "/Users/shen/Work/Code/Readoor"))
# AutoPacking 目录
AUTOPACKING_DIR = PROJECT_ROOT / "AutoPacking"
# config.json 路径
CONFIG_JSON_PATH = AUTOPACKING_DIR / "config.json"
# 打包基础目录
BUILD_BASE_DIR = Path(os.getenv("BUILD_BASE_DIR", "/Users/shen/Documents"))
# Git 分支源码目录
# GIT_SOURCE_BASE: 分支源码的根目录,每个分支一个子目录
# GIT_REMOTE_URL: 远程仓库地址,分支目录不存在时自动 clone
GIT_SOURCE_BASE = Path(os.getenv("GIT_SOURCE_BASE", str(PROJECT_ROOT.parent / "ReadoorBranches")))
GIT_REMOTE_URL = os.getenv("GIT_REMOTE_URL", "")
def get_source_dir(branch: str) -> Path:
"""获取指定分支的源码目录"""
return GIT_SOURCE_BASE / branch
# 需要拷贝的目录和文件
COPY_ITEMS = [
"readoor",
"readoor.xcodeproj",
"readoorTests",
"AutoPacking",
"podfile",
"Pods",
"Podfile.lock",
"readoor.xcworkspace",
]
# 服务端口
BACKEND_PORT = int(os.getenv("BACKEND_PORT", "8000"))
# 数据库路径
DATABASE_URL = f"sqlite:///{Path(__file__).parent / 'build_server.db'}"
# WebSocket 日志队列最大长度
LOG_QUEUE_MAX_SIZE = 1000
# 默认最大并行打包数
DEFAULT_MAX_CONCURRENT_BUILDS = int(os.getenv("MAX_CONCURRENT_BUILDS", "2"))
# 默认打包目录保留时间(小时)
DEFAULT_BUILD_DIR_RETENTION_HOURS = int(os.getenv("BUILD_DIR_RETENTION_HOURS", "24"))
# 管理员账号配置
ADMIN_USERNAME = os.getenv("ADMIN_USERNAME", "admin")
ADMIN_PASSWORD = os.getenv("ADMIN_PASSWORD", "admin123")