/
gr.ev.vl
/
TestGen
Обзор
Документация
Войти
/
gr.ev.vl
/
TestGen
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master2
scripts/setup_first_run.cmd
606 строк
18 KB
gr.ev.vl
Initial commit
06 июн 2026, 02:41
06 июн 2026, 02:41
02fb1fb
Код
Авторство
О чём код?
@echo off chcp 1251 >nul setlocal enabledelayedexpansion :: ============================================================================= :: TestGen � ��������� ��������� � ������������� ������� :: :: ��� ������: :: 1. ��������� � ������������� ����������� (Python, Node.js) :: 2. ������ ����������� ��������� Python :: 3. ������������� backend-����������� :: 4. ������������� frontend-����������� :: 5. ������ .env ���� � ����������� :: 6. �������������� �������� �� (datas/) :: 7. ������ ��������� ������ (�������) :: 8. ��������� �� ���������� ������� (������, �������������) :: 9. ��������� �������� ������ (�����, ����) :: 10. ��������� ���������� � ������� :: ============================================================================= title TestGen � ��������� ��������� ������� set "SCRIPT_DIR=%~dp0" set "SCRIPT_DIR=%SCRIPT_DIR:~0,-1%" for %%i in ("%SCRIPT_DIR%") do set "PROJECT_DIR=%%~dpi" set "PROJECT_DIR=%PROJECT_DIR:~0,-1%" set "BACKEND_DIR=%PROJECT_DIR%\backend" set "FRONTEND_DIR=%PROJECT_DIR%\frontend" set "ENV_FILE=%BACKEND_DIR%\.env" cd /d "%PROJECT_DIR%" echo. echo �==============================================================� echo � TestGen � ��������� ��������� ������� � echo � ���������� � ������� ������� � echo L==============================================================- echo. :: ============================================================================= :: 1. �������� Python :: ============================================================================= echo [1/10] �������� Python... set "PYTHON_OK=0" where python >nul 2>&1 if %errorlevel% equ 0 ( for /f "tokens=2" %%v in ('python --version 2^>^&1') do set "PY_VER=%%v" echo [OK] Python !PY_VER! set "PYTHON_OK=1" ) else ( echo [X] Python �� ������. echo ���������� Python 3.12+: https://www.python.org/downloads/ pause exit /b 1 ) echo. :: ============================================================================= :: 2. �������� Node.js :: ============================================================================= echo [2/10] �������� Node.js... set "NODE_OK=0" where node >nul 2>&1 if %errorlevel% equ 0 ( for /f "tokens=2" %%v in ('node --version 2^>^&1') do set "NODE_VER=%%v" echo [OK] Node.js !NODE_VER! set "NODE_OK=1" ) else ( echo [X] Node.js �� ������. echo ���������� Node.js 20+: https://nodejs.org/ pause exit /b 1 ) echo. :: ============================================================================= :: 3. ��������� Backend :: ============================================================================= echo [3/10] ��������� Backend... cd /d "%BACKEND_DIR%" :: �������� ������������ ��������� if not exist ".venv\Scripts\python.exe" ( echo �������� ������������ ���������... python -m venv .venv if %errorlevel% neq 0 ( echo [X] ������ �������� ������������ ���������. pause exit /b 1 ) echo [OK] ����������� ��������� �������. ) else ( echo [OK] ����������� ��������� ����������. ) :: ��������� call .venv\Scripts\activate.bat :: ���������� pip echo ���������� pip... python -m pip install --upgrade pip --quiet 2>nul :: ��������� ������������ echo ��������� ������������... where uv >nul 2>&1 if %errorlevel% equ 0 ( echo ������������ uv... uv sync --group dev 2>&1 if %errorlevel% neq 0 ( echo [!] uv �� ��������, ������� pip... goto :install_pip ) ) else ( :install_pip echo ������������ pip... if exist "requirements.txt" ( pip install -r requirements.txt --quiet 2>nul ) else ( :: ��������� �������� ������� pip install fastapi uvicorn starlette sqlalchemy psycopg[binary] alembic redis celery pydantic pydantic-settings openai anthropic google-generativeai python-jose[cryptography] passlib[bcrypt] bcrypt httpx python-multipart structlog python-dotenv pyyaml --quiet 2>nul ) :: Dev-����������� pip install pytest pytest-asyncio pytest-cov pytest-mock factory-boy httpx ruff mypy pre-commit ipython --quiet 2>nul ) echo [OK] ����������� �����������. echo. :: ============================================================================= :: 4. �������� .env ����� :: ============================================================================= echo [4/10] �������� .env �����... if not exist "%ENV_FILE%" ( echo �������� .env � ����������� �� ���������... ( echo # TestGen � ������������ echo APP_NAME=TestGen echo APP_VERSION=0.1.0 echo ENVIRONMENT=development echo DEBUG=true echo LOG_LEVEL=DEBUG echo. echo # ������ echo STORAGE_MODE=file echo CACHE_MODE=file echo TASK_MODE=sync echo. echo # ������������ echo SECRET_KEY=dev-secret-key-change-in-production-12345 echo ACCESS_TOKEN_EXPIRE_MINUTES=30 echo REFRESH_TOKEN_EXPIRE_DAYS=30 echo ENCRYPTION_KEY=abcdefghijklmnopqrstuvwxyz123456 echo. echo # ���� ������ ^(������ ��� STORAGE_MODE=database^) echo DB_HOST=localhost echo DB_PORT=5432 echo DB_NAME=testgen echo DB_USER=testgen echo DB_PASSWORD=password echo. echo # Redis ^(������ ��� CACHE_MODE=redis ��� TASK_MODE=celery^) echo REDIS_HOST=localhost echo REDIS_PORT=6379 echo REDIS_DB=0 echo. echo # ��������� echo STORAGE_PATH=./storage echo DATA_PATH=./datas echo. echo # CORS echo CORS_ORIGINS=["http://localhost:5173","http://localhost:3000"] ) > "%ENV_FILE%" echo [OK] ���� .env ������. ) else ( echo [OK] ���� .env ��� ����������. ) echo. :: ============================================================================= :: 5. ������������� �������� ���� ������ :: ============================================================================= echo [5/10] ������������� �������� ���� ������... set "PYTHONPATH=%BACKEND_DIR%\src;%PYTHONPATH%" :: �������� ��������� ������ python -c " import sys sys.path.insert(0, 'src') from src.testgen.infrastructure.storage.file_db import init_file_db from src.testgen.config import settings db = init_file_db(settings.storage.DATA_PATH) tables = db.get_all_tables() print(f' ������ �������: {len(tables)}') for t in sorted(tables): print(f' - {t}') " 2>&1 if %errorlevel% neq 0 ( echo [!] �������������� ��� �������� ��������� ������. echo ��������� ����� � ���������� datas/ ) else ( echo [OK] ��������� ������ �������. ) echo. :: ============================================================================= :: 6. �������� ����������������� ������� :: ============================================================================= echo [6/10] �������� ����������������� �������... python -c " import sys sys.path.insert(0, 'src') from src.testgen.infrastructure.storage.file_db import get_file_db from src.testgen.config import settings db = get_file_db(settings.storage.DATA_PATH) prompts = [ { 'name': 'question_generation_v1', 'prompt_type': 'question_generation', 'description': '������� ��������� �������� ��������', 'is_system': True, 'is_active': True, }, { 'name': 'misconception_generation_v1', 'prompt_type': 'misconception_generation', 'description': '��������� ������� �����������', 'is_system': True, 'is_active': True, }, { 'name': 'distractor_generation_v1', 'prompt_type': 'distractor_generation', 'description': '��������� ������������', 'is_system': True, 'is_active': True, }, { 'name': 'question_verification_v1', 'prompt_type': 'question_verification', 'description': '����������� ��������', 'is_system': True, 'is_active': True, }, { 'name': 'distractor_verification_v1', 'prompt_type': 'distractor_verification', 'description': '����������� ������������', 'is_system': True, 'is_active': True, }, ] created = 0 for pdata in prompts: existing = db.get_by_field('prompts', 'name', pdata['name']) if not existing: prompt = db.create('prompts', pdata) # ������ ������ ������ db.create('prompt_versions', { 'prompt_id': prompt['id'], 'version_number': 1, 'content': f'���������� �������� �������. ���: {pdata[\"prompt_type\"]}', 'variables': {}, 'response_format': {}, 'is_current': True, 'change_description': '��������� ������', }) created += 1 print(f' ������� �������: {created}') " 2>&1 if %errorlevel% neq 0 ( echo [!] �������������� ��� �������� �������. ) else ( echo [OK] ����������������� ������ �������. ) echo. :: ============================================================================= :: 7. �������� �������������� :: ============================================================================= echo [7/10] �������� ��������������... echo. echo ������ �� ���������: echo Email: admin@testgen.local echo ������: Admin123! echo. set /p CREATE_ADMIN="������� ��������������? (y/n) [y]: " if "%CREATE_ADMIN%"=="" set "CREATE_ADMIN=y" if /i "%CREATE_ADMIN%"=="y" ( set /p ADMIN_EMAIL="Email [admin@testgen.local]: " if "!ADMIN_EMAIL!"=="" set "ADMIN_EMAIL=admin@testgen.local" set /p ADMIN_PASS="������ [Admin123!]: " if "!ADMIN_PASS!"=="" set "ADMIN_PASS=Admin123!" set /p ADMIN_NAME="��� [�������������]: " if "!ADMIN_NAME!"=="" set "ADMIN_NAME=�������������" echo. echo �������� ������������... python -c " import sys sys.path.insert(0, 'src') from src.testgen.infrastructure.storage.file_db import get_file_db from src.testgen.core.utils.hashing import hash_password from src.testgen.config import settings db = get_file_db(settings.storage.DATA_PATH) existing = db.get_by_field('users', 'email', '!ADMIN_EMAIL!') if existing: print(' [!] ������������ ��� ����������') else: db.create('users', { 'email': '!ADMIN_EMAIL!', 'password_hash': hash_password('!ADMIN_PASS!'), 'full_name': '!ADMIN_NAME!', 'role': 'admin', 'is_active': True, }) print(' [OK] ������������� ������') " 2>&1 if !errorlevel! neq 0 ( echo [!] ������ �������� ��������������. ) else ( echo [OK] ������������� ������. ) ) else ( echo ���������. ) echo. :: ============================================================================= :: 8. �������� �������� ������ :: ============================================================================= echo [8/10] �������� �������� ������... echo. echo �������� ������ ��������: echo - ����-���� � ������ � ��������� echo - ������� ����� echo - ������ ���������� ����� echo - ��������� ������������� echo. set /p SEED_DATA="��������� �������� ������? (y/n) [n]: " if /i "!SEED_DATA!"=="y" ( echo. echo �������� ������... python -c " import sys sys.path.insert(0, 'src') from src.testgen.infrastructure.storage.file_db import get_file_db from src.testgen.core.utils.hashing import hash_password from src.testgen.config import settings db = get_file_db(settings.storage.DATA_PATH) # ������������� teacher = db.create('users', { 'email': 'teacher@testgen.local', 'password_hash': hash_password('Teacher123!'), 'full_name': '���� ��������������', 'role': 'teacher', 'department': '������� ������', 'is_active': True, }) print(f' �������������: {teacher[\"email\"]}') # ���� course = db.create('courses', { 'code': 'DEMO101', 'name': '���������������� ����', 'description': '���� ��� ������������ ������������ �������', 'faculty': '����-���������', 'semester': 1, 'status': 'active', 'created_by': teacher['id'], }) print(f' ����: {course[\"name\"]} ({course[\"code\"]})') # ������� ����� db.create('passports', { 'course_id': course['id'], 'version_number': 1, 'audience_description': '�������� ����������������� �����', 'course_goals': '������������ � ������������� �������', 'restrictions': '��� �����������', 'style_requirements': '�������������', 'is_active': True, 'created_by': teacher['id'], }) print(' ������� ����� ������') # ������ ���������� for level in ['knowledge', 'comprehension', 'application']: db.create('bloom_taxonomy_levels', { 'course_id': course['id'], 'level': level, 'is_enabled': True, }) print(' ������ ���������� ����� ���������') # ���� topic = db.create('topics', { 'course_id': course['id'], 'name': '�������� � �������', 'description': '�������� ������� � �����������', 'order_number': 1, }) print(f' ����: {topic[\"name\"]}') # ������� for i, name in enumerate(['�������� �����������', '�������� ���������', '������������ ����������']): db.create('subtopics', { 'topic_id': topic['id'], 'name': name, 'order_number': i + 1, }) print(f' ������� �������: 3') print() print(' �������� ������ ���������!') print() print(' ������ ��� �����:') print(' �������������: admin@testgen.local / Admin123!') print(' �������������: teacher@testgen.local / Teacher123!') " 2>&1 if !errorlevel! neq 0 ( echo [!] ������ �������� ������. ) else ( echo [OK] �������� ������ ���������. ) ) else ( echo ���������. ) echo. :: ============================================================================= :: 9. ��������� Frontend :: ============================================================================= echo [9/10] ��������� Frontend... cd /d "%FRONTEND_DIR%" if exist "node_modules" ( echo [OK] node_modules ����������. ) else ( echo ��������� npm-������������... call npm install if %errorlevel% neq 0 ( echo [!] ������ ��������� npm-������������. echo ���������� ��������� �������: cd frontend ^&^& npm install ) else ( echo [OK] ����������� �����������. ) ) echo. :: ============================================================================= :: 10. �������� ���������� :: ============================================================================= echo [10/10] �������� ����������... cd /d "%PROJECT_DIR%" echo. echo �������� ��������� ������... if exist "%BACKEND_DIR%\datas" ( echo [OK] ���������� datas/ ����������. set "COUNT=0" for %%f in ("%BACKEND_DIR%\datas\*.json") do set /a COUNT+=1 echo [OK] ������ ������: !COUNT! ) else ( echo [!] ���������� datas/ �� �������. ) echo. echo �������� backend... if exist "%BACKEND_DIR%\.venv\Scripts\python.exe" ( echo [OK] ����������� ��������� Python. ) else ( echo [!] ����������� ��������� �� �������. ) echo. echo �������� frontend... if exist "%FRONTEND_DIR%\node_modules" ( echo [OK] node_modules. ) else ( echo [!] node_modules �� �������. ) :: ============================================================================= :: �������� �������� ������� :: ============================================================================= echo. echo �������� �������� �������... :: run_backend.cmd ( echo @echo off echo chcp 65001 ^>nul echo title TestGen Backend echo cd /d "%BACKEND_DIR%" echo call .venv\Scripts\activate.bat echo set "PYTHONPATH=%BACKEND_DIR%\src;%%PYTHONPATH%%" echo echo ============================================ echo echo TestGen Backend echo echo http://localhost:8000 echo echo Docs: http://localhost:8000/api/docs echo echo ============================================ echo uvicorn src.testgen.main:app --reload --host 0.0.0.0 --port 8000 --log-level info echo pause ) > "%SCRIPT_DIR%\run_backend.cmd" :: run_frontend.cmd ( echo @echo off echo chcp 65001 ^>nul echo title TestGen Frontend echo cd /d "%FRONTEND_DIR%" echo echo ============================================ echo echo TestGen Frontend echo echo http://localhost:5173 echo echo ============================================ echo call npm run dev echo pause ) > "%SCRIPT_DIR%\run_frontend.cmd" :: run_all.cmd ( echo @echo off echo chcp 65001 ^>nul echo title TestGen echo echo ============================================ echo echo ������ TestGen echo echo ============================================ echo echo. echo echo ������ Backend... echo start "TestGen Backend" cmd /c "%SCRIPT_DIR%\run_backend.cmd" echo timeout /t 5 /nobreak ^>nul echo echo ������ Frontend... echo start "TestGen Frontend" cmd /c "%SCRIPT_DIR%\run_frontend.cmd" echo echo. echo echo ============================================ echo echo ������� ��������! echo echo Backend: http://localhost:8000 echo echo Frontend: http://localhost:5173 echo echo ============================================ echo pause ) > "%SCRIPT_DIR%\run_all.cmd" echo [OK] ������� �������: run_backend.cmd, run_frontend.cmd, run_all.cmd :: ============================================================================= :: ���������� :: ============================================================================= echo. echo �==============================================================� echo � ��������� ���������! � echo L==============================================================- echo. echo ������ ��� �����: echo �������������: admin@testgen.local / Admin123! if /i "%SEED_DATA%"=="y" ( echo �������������: teacher@testgen.local / Teacher123! ) echo. echo ������ ����������: echo scripts\run_all.cmd (��� �������) echo scripts\run_backend.cmd (������ backend) echo scripts\run_frontend.cmd (������ frontend) echo. echo ������� � ��������: echo Frontend: http://localhost:5173 echo API Docs: http://localhost:8000/api/docs echo Health: http://localhost:8000/health echo. echo ��� �������� �� PostgreSQL/Redis/Celery: echo �������� STORAGE_MODE=database � backend\.env echo. pause exit /b 0