update project configuration and add development tools

- Add Python virtual environment patterns to .gitignore
- Replace .codebuddy with .clinerules in .gitignore
- Add .pid file for process tracking
- Add comprehensive .pylintrc configuration for Python linting
- Update start.bat with English translations and simplified functions
This commit is contained in:
Falck
2026-04-19 12:00:02 +08:00
parent 282a42081b
commit e72818399c
76 changed files with 953 additions and 152 deletions

230
start.bat
View File

@@ -1,56 +1,31 @@
@echo off
chcp 65001 >nul 2>&1
setlocal enabledelayedexpansion
:: ═══════════════════════════════════════════════════════════
:: FutureOSS 智能启动脚本 - Windows
:: 自动检测环境 / 安装依赖 / 进度显示 / 守护重启
:: ═══════════════════════════════════════════════════════════
:: FutureOSS Smart Startup Script - Windows
cd /d "%~dp0"
:: ── 处理命令行参数 ──
:: Handle command line parameters
if "%1"=="--help" goto :show_help
if "%1"=="-h" goto :show_help
if "%1"=="--version" goto :show_version
if "%1"=="-v" goto :show_version
:: ── 颜色代码 ──
for /F "tokens=1,2 delims=#" %%a in ('"prompt #$H#$E# & echo on & for %%b in (1) do rem"') do (
set "DEL=%%a"
)
:: ── 工具函数 ──
call :colorEcho 0B "[信息] 环境检测中..."
call :colorEcho 0A "[成功] 检测完成"
call :colorEcho 0E "[警告] 某些组件缺失"
call :colorEcho 0C "[错误] 检测失败"
:: ── Logo ──
echo.
call :colorEcho 0B " ███████╗ ██████╗ ██████╗ ██████╗ ██████╗ ██████╗ "
call :colorEcho 0B " ██╔════╝ ██╔══██╗ ██╔══██╗ ██╔══██╗ ██╔══██╗██╔════╝ "
call :colorEcho 0B " █████╗ ██████╔╝ ██████╔╝ ██████╔╝ ██║ ██║██║ ███╗"
call :colorEcho 0B " ██╔══╝ ██╔══██╗ ██╔══██╗ ██╔══██╗ ██║ ██║██║ ██║"
call :colorEcho 0B " ██║ ██║ ██║ ██║ ██║ ██║ ██║ ██████╔╝╚██████╔╝"
call :colorEcho 0B " ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚═════╝ "
echo.
call :colorEcho 0F " 开发者通用工具套组 · 一切皆为插件"
call :colorEcho 07 " https://gitee.com/starlight-apk/feature-oss"
echo ========================================
echo FutureOSS Startup Script - Windows
echo ========================================
echo.
:: ── 检查是否已有实例在运行 ──
:: Check if an instance is already running
call :check_pid
if %errorlevel% neq 0 (
call :colorEcho 0C "[错误] 检测到已有实例在运行,请先停止"
echo [ERROR] An instance is already running, please stop it first
pause
exit /b 1
)
:: ═══════════════════════════════════════════════════════════
:: 1. 检测 Python
:: ═══════════════════════════════════════════════════════════
call :colorEcho 0B "[信息] 检测 Python..."
:: 1. Detect Python
echo [INFO] Detecting Python...
set "PYTHON_CMD="
for %%p in (python python3 py py3) do (
@@ -63,47 +38,43 @@ for %%p in (python python3 py py3) do (
:found_python
if "%PYTHON_CMD%"=="" (
call :colorEcho 0C "[错误] 未找到 Python请先安装 Python 3.10+"
call :colorEcho 0E "[提示] 下载地址: https://www.python.org/downloads/"
echo [ERROR] Python not found, please install Python 3.10+
echo [TIP] Download from: https://www.python.org/downloads/
pause
exit /b 1
)
for /f "tokens=*" %%i in ('%PYTHON_CMD% --version 2^>^&1') do set "PY_VER=%%i"
call :colorEcho 0A "[成功] %PY_VER%"
echo [SUCCESS] %PY_VER%
:: 显示系统信息
call :colorEcho 0B "[信息] 系统信息:"
:: Display system info
echo [INFO] System Information:
echo OS: Windows
echo 工作目录: %CD%
echo 时间: %date% %time%
echo Working Directory: %CD%
echo Time: %date% %time%
:: ═══════════════════════════════════════════════════════════
:: 2. 虚拟环境
:: ═══════════════════════════════════════════════════════════
:: 2. Virtual Environment
echo.
call :colorEcho 0B "[信息] 配置 Python 环境..."
echo [INFO] Configuring Python environment...
if not exist ".venv" (
call :colorEcho 0E "[信息] 创建虚拟环境..."
echo [INFO] Creating virtual environment...
%PYTHON_CMD% -m venv .venv >nul 2>&1
if errorlevel 1 (
call :colorEcho 0C "[错误] 无法创建虚拟环境"
echo [ERROR] Cannot create virtual environment
pause
exit /b 1
)
call :colorEcho 0A "[成功] 虚拟环境已创建"
echo [SUCCESS] Virtual environment created
) else (
call :colorEcho 0A "[成功] 虚拟环境已存在"
echo [SUCCESS] Virtual environment exists
)
call .venv\Scripts\activate.bat >nul 2>&1
:: ═══════════════════════════════════════════════════════════
:: 3. 安装依赖
:: ═══════════════════════════════════════════════════════════
:: 3. Install Dependencies
echo.
call :colorEcho 0B "[信息] 安装 Python 依赖..."
echo [INFO] Installing Python dependencies...
set "DEPS=click pyyaml websockets psutil cryptography"
set "TOTAL=5"
@@ -111,7 +82,7 @@ set "CURRENT=0"
for %%d in (%DEPS%) do (
set /a CURRENT+=1
call :printProgress !CURRENT! !TOTAL! "安装 %%d"
call :printProgress !CURRENT! !TOTAL! "Installing %%d"
%PYTHON_CMD% -c "import %%d" 2>nul
if errorlevel 1 (
@@ -120,40 +91,35 @@ for %%d in (%DEPS%) do (
)
echo.
echo.
call :colorEcho 0A "[成功] Python 依赖安装完成"
echo [SUCCESS] Python dependencies installed
:: 安装项目依赖
:: Install project dependencies
if exist "pyproject.toml" (
call :colorEcho 0E "[信息] 安装项目配置依赖..."
echo [INFO] Installing project configuration dependencies...
pip install -e . -q 2>nul
)
if exist "requirements.txt" (
call :colorEcho 0E "[信息] 安装 requirements.txt..."
echo [INFO] Installing requirements.txt...
pip install -r requirements.txt -q 2>nul
)
:: ═══════════════════════════════════════════════════════════
:: 4. 检查 PHP
:: ═══════════════════════════════════════════════════════════
:: 4. Check PHP
echo.
call :colorEcho 0B "[信息] 检查 PHP..."
echo [INFO] Checking PHP...
where php >nul 2>&1
if errorlevel 1 (
call :colorEcho 0E "[警告] PHP 未安装WebUI 可能无法正常工作"
call :colorEcho 07 "[提示] 安装: choco install php 或从 https://windows.php.net/download/ 下载"
echo [WARNING] PHP not installed, WebUI may not work properly
echo [TIP] Install: choco install php or download from https://windows.php.net/download/
) else (
for /f "tokens=*" %%i in ('php --version 2^>^&1 ^| findstr /r "PHP"') do set "PHP_VER=%%i"
call :colorEcho 0A "[成功] !PHP_VER!"
echo [SUCCESS] !PHP_VER!
)
:: ═══════════════════════════════════════════════════════════
:: 5. 创建数据目录
:: ═══════════════════════════════════════════════════════════
:: 5. Create Data Directories
echo.
call :colorEcho 0B "[信息] 初始化数据目录..."
echo [INFO] Initializing data directories...
set "DIRS=data data\html-render data\web-toolkit data\plugin-storage data\DCIM data\pkg data\signature-verifier\keys\private data\signature-verifier\keys\public logs"
@@ -161,30 +127,28 @@ for %%d in (%DIRS%) do (
if not exist "%%d" (
mkdir "%%d" >nul 2>&1
if errorlevel 1 (
call :colorEcho 0C "[错误] 无法创建目录: %%d"
echo [ERROR] Cannot create directory: %%d
)
)
)
call :colorEcho 0A "[成功] 数据目录已就绪"
echo [SUCCESS] Data directories ready
:: ═══════════════════════════════════════════════════════════
:: 6. 启动服务
:: ═══════════════════════════════════════════════════════════
:: 6. Start Service
echo.
call :colorEcho 0B "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
call :colorEcho 0B " 启动 FutureOSS"
call :colorEcho 0B "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ========================================
echo Starting FutureOSS
echo ========================================
echo.
:: 创建 PID 文件
:: Create PID file
call :create_pid "!random!"
if "%1"=="--daemon" goto :daemon_mode
if "%1"=="-d" goto :daemon_mode
:: 前台模式
call :colorEcho 0F "运行中... 按 Ctrl+C 停止"
:: Foreground mode
echo Running... Press Ctrl+C to stop
echo.
set "RESTART_DELAY=3"
@@ -196,21 +160,21 @@ set "MAX_RESTARTS=10"
set "EXIT_CODE=%errorlevel%"
if %EXIT_CODE% equ 0 (
call :colorEcho 0A "[成功] 服务正常退出"
echo [SUCCESS] Service exited normally
goto :end
)
:: 检查是否超过最大重启次数
:: Check if max restarts exceeded
if %RESTART_COUNT% geq %MAX_RESTARTS% (
call :colorEcho 0C "[错误] 达到最大重启次数 (%MAX_RESTARTS%),停止服务"
echo [ERROR] Reached maximum restart count (%MAX_RESTARTS%), stopping service
goto :end
)
set /a RESTART_COUNT+=1
call :colorEcho 0E "[警告] 服务异常退出 (code: %EXIT_CODE%)!RESTART_DELAY!s 后重启... (!RESTART_COUNT!/%MAX_RESTARTS% 次)"
echo [WARNING] Service exited abnormally (code: %EXIT_CODE%), restarting in !RESTART_DELAY!s... (!RESTART_COUNT!/%MAX_RESTARTS%)
timeout /t !RESTART_DELAY! /nobreak >nul
:: 指数退避 (最大 60 秒)
:: Exponential backoff (max 60 seconds)
if !RESTART_DELAY! lss 60 (
set /a RESTART_DELAY=!RESTART_DELAY! * 2
if !RESTART_DELAY! gtr 60 set "RESTART_DELAY=60"
@@ -219,10 +183,10 @@ if !RESTART_DELAY! lss 60 (
goto :loop
:daemon_mode
call :colorEcho 0E "[警告] Windows 守护模式需要额外配置"
call :colorEcho 07 "[提示] 建议使用任务计划程序或 nssm 工具实现"
echo [WARNING] Windows daemon mode requires additional configuration
echo [TIP] Use Task Scheduler or nssm tool instead
echo.
call :colorEcho 0B "[信息] 启动后台服务..."
echo [INFO] Starting background service...
start /b %PYTHON_CMD% -m oss.cli serve > logs\daemon.log 2>&1
goto :end
@@ -230,65 +194,41 @@ goto :end
call :cleanup
call .venv\Scripts\deactivate.bat >nul 2>&1
echo.
call :colorEcho 0B "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
call :colorEcho 0F " FutureOSS 已停止"
call :colorEcho 0B "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ========================================
echo FutureOSS Stopped
echo ========================================
pause
exit /b 0
:: ── 进度条函数 ──
:: Progress bar function
:printProgress
set /a "pct=%1 * 100 / %2"
set /a "filled=pct / 2"
set /a "empty=50-filled"
set "bar="
for /l %%i in (1,1,%filled%) do set "bar=!bar!"
for /l %%i in (1,1,%empty%) do set "bar=!bar!"
for /l %%i in (1,1,%filled%) do set "bar=!bar!#"
for /l %%i in (1,1,%empty%) do set "bar=!bar!-"
echo [!bar!] !pct!%% - %3
exit /b 0
:: ── 颜色输出函数 ──
:colorEcho
set "params=%1"
set "msg=%~2"
call :colorText %params% "%msg%"
exit /b 0
:colorText
<nul set /p "=%DEL%"
findstr /v /a:%1 /R "^$" "%DEL%" nul
<nul set /p "=%DEL%%DEL%%DEL%%DEL%%DEL%%DEL%%DEL%"
echo %~2
exit /b 0
:: ── 检查命令是否存在 ──
:: Check if command exists
:command_exists
where %1 >nul 2>&1
exit /b %errorlevel%
:: ── 获取当前时间戳 ──
:: Get current timestamp
:get_timestamp
for /f "tokens=1-3 delims=/ " %%a in ('date /t') do set "T_DATE=%%c-%%a-%%b"
for /f "tokens=1-3 delims=: " %%a in ('time /t') do set "T_TIME=%%a:%%b:%%c"
set "TIMESTAMP=%T_DATE% %T_TIME%"
exit /b 0
:: ── 打印分隔线 ──
:: Print separator
:print_separator
echo ═══════════════════════════════════════════════════════════
echo ========================================
exit /b 0
:: ── 打印带颜色的状态 ──
:print_status
set "status_type=%~1"
set "status_msg=%~2"
if "%status_type%"=="info" call :colorEcho 0B "[信息] %status_msg%"
if "%status_type%"=="success" call :colorEcho 0A "[成功] %status_msg%"
if "%status_type%"=="warn" call :colorEcho 0E "[警告] %status_msg%"
if "%status_type%"=="error" call :colorEcho 0C "[错误] %status_msg%"
exit /b 0
:: ── 健康检查 ──
:: Health check
:health_check
set "check_url=%~1"
set "max_retries=%~2"
@@ -299,33 +239,33 @@ set "retry_count=0"
set /a retry_count+=1
curl -s "%check_url%" >nul 2>&1
if %errorlevel% equ 0 (
call :colorEcho 0A "[健康检查] 服务已就绪"
echo [HEALTH CHECK] Service is ready
exit /b 0
)
if %retry_count% geq %max_retries% (
call :colorEcho 0C "[健康检查] 服务启动超时"
echo [HEALTH CHECK] Service startup timeout
exit /b 1
)
timeout /t 1 /nobreak >nul
goto :health_loop
:: ── 创建 PID 文件 ──
:: Create PID file
:create_pid
echo %~1 > .pid
exit /b 0
:: ── 删除 PID 文件 ──
:: Remove PID file
:remove_pid
if exist ".pid" del ".pid"
exit /b 0
:: ── 检查 PID 文件 ──
:: Check PID file
:check_pid
if exist ".pid" (
set /p PID=<.pid
tasklist /fi "pid eq %PID%" 2>nul | find "%PID%" >nul
if %errorlevel% equ 0 (
call :colorEcho 0E "[警告] 服务已在运行 (PID: %PID%)"
echo [WARNING] Service already running (PID: %PID%)
exit /b 1
) else (
call :remove_pid
@@ -333,34 +273,34 @@ if exist ".pid" (
)
exit /b 0
:: ── 显示帮助信息 ──
:: Show help information
:show_help
echo.
call :colorEcho 0F "FutureOSS 启动脚本 - Windows 版本"
echo FutureOSS Startup Script - Windows Version
echo.
echo 用法: start.bat [选项]
echo Usage: start.bat [options]
echo.
echo 选项:
echo --daemon, -d 以后台模式运行Windows 建议使用任务计划程序)
echo --help, -h 显示此帮助信息
echo --version, -v 显示版本信息
echo Options:
echo --daemon, -d Run in background mode (Windows recommends Task Scheduler)
echo --help, -h Show this help message
echo --version, -v Show version information
echo.
echo 示例:
echo start.bat 前台运行模式
echo start.bat --daemon 后台运行模式
echo Examples:
echo start.bat Foreground mode
echo start.bat --daemon Background mode
echo.
exit /b 0
:: ── 显示版本信息 ──
:: Show version information
:show_version
echo FutureOSS v1.0.0
echo 基于 Python 的开发者通用工具套组
echo Developer toolkit based on Python
echo.
exit /b 0
:: ── 清理函数 ──
:: Cleanup function
:cleanup
call :colorEcho 0E "[信息] 正在清理..."
echo [INFO] Cleaning up...
call :remove_pid
call :colorEcho 0A "[成功] 清理完成"
echo [SUCCESS] Cleanup completed
exit /b 0