feat: добавить общий виртуальный счёт, справку и восстановление позиций
This commit is contained in:
1 parent
6aa76064dc
commit
c5aed5b970
29 files changed
+3600
-224
No files matched your search
@@ -12,20 +12,27 @@ $Host.UI.RawUI.WindowTitle = "Симулятор"
|
||||
$VenvPy = Join-Path $Dir ".venv\Scripts\python.exe"
|
||||
$VenvPyw = Join-Path $Dir ".venv\Scripts\pythonw.exe"
|
||||
|
||||
function Test-Python($Executable) {
|
||||
try {
|
||||
& $Executable -c "import sys; sys.exit(0 if sys.version_info >= (3, 11) else 1)" 2>$null
|
||||
return $LASTEXITCODE -eq 0
|
||||
} catch { return $false }
|
||||
}
|
||||
|
||||
function Find-Python {
|
||||
foreach ($v in "3.13", "3.12", "3.11") {
|
||||
try {
|
||||
$exe = & py "-$v" -c "import sys; print(sys.executable)" 2>$null
|
||||
if ($LASTEXITCODE -eq 0 -and $exe) { return $exe.Trim() }
|
||||
if ($LASTEXITCODE -eq 0 -and $exe -and (Test-Python $exe.Trim())) { return $exe.Trim() }
|
||||
} catch {}
|
||||
}
|
||||
foreach ($d in "Python313", "Python312", "Python311") {
|
||||
$p = Join-Path $env:LOCALAPPDATA "Programs\Python\$d\python.exe"
|
||||
if (Test-Path $p) { return $p }
|
||||
if ((Test-Path $p) -and (Test-Python $p)) { return $p }
|
||||
}
|
||||
try {
|
||||
$exe = & python -c "import sys; assert sys.version_info >= (3, 11); print(sys.executable)" 2>$null
|
||||
if ($LASTEXITCODE -eq 0 -and $exe) { return $exe.Trim() }
|
||||
if ($LASTEXITCODE -eq 0 -and $exe -and (Test-Python $exe.Trim())) { return $exe.Trim() }
|
||||
} catch {}
|
||||
return $null
|
||||
}
|
||||
@@ -36,7 +43,8 @@ function Fail($text) {
|
||||
exit 1
|
||||
}
|
||||
|
||||
if (-not (Test-Path $VenvPy)) {
|
||||
if (-not (Test-Python $VenvPy)) {
|
||||
Write-Host "Окружение отсутствует или не работает. Подбираю Python 3.11+..." -ForegroundColor Yellow
|
||||
$py = Find-Python
|
||||
if (-not $py) {
|
||||
Write-Host "Python не найден. Ставлю Python 3.12 через winget..." -ForegroundColor Yellow
|
||||
@@ -48,18 +56,23 @@ if (-not (Test-Path $VenvPy)) {
|
||||
$py = Find-Python
|
||||
if (-not $py) { Fail "Python установлен, но ещё не виден. Закройте окно и запустите файл ещё раз." }
|
||||
}
|
||||
$VenvDir = Join-Path $Dir ".venv"
|
||||
if (Test-Path $VenvDir) {
|
||||
$Backup = ".venv.backup-" + [Guid]::NewGuid().ToString("N")
|
||||
Rename-Item -LiteralPath $VenvDir -NewName $Backup
|
||||
Write-Host "Старое окружение сохранено: $Backup"
|
||||
}
|
||||
Write-Host "Python: $py"
|
||||
Write-Host "Создаю окружение программы (.venv)..."
|
||||
& $py -m venv (Join-Path $Dir ".venv")
|
||||
if ($LASTEXITCODE -ne 0 -or -not (Test-Path $VenvPy)) { Fail "Не удалось создать .venv" }
|
||||
}
|
||||
|
||||
& $VenvPy -c "import sys; assert sys.version_info >= (3, 11), 'Python 3.11+ required'"
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
Fail "Окружение .venv использует старый Python. Переименуйте .venv и повторите установку с Python 3.11 или новее."
|
||||
if (-not (Test-Python $VenvPy)) {
|
||||
Fail "Не удалось запустить Python из нового окружения .venv."
|
||||
}
|
||||
Write-Host "Проверяю библиотеки..."
|
||||
& $VenvPy -m pip install --disable-pip-version-check -q -r (Join-Path $Dir "requirements.txt")
|
||||
Write-Host "Проверяю библиотеки. Ниже отображается ход установки; для загрузки нужен интернет..."
|
||||
& $VenvPy -m pip install --disable-pip-version-check --timeout 30 --retries 2 -r (Join-Path $Dir "requirements.txt")
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
Fail "Не удалось установить библиотеки. Проверьте интернет (и VPN, если сайты у вас заблокированы) и запустите ещё раз."
|
||||
}
|
||||
@@ -72,6 +85,6 @@ Write-Host ""
|
||||
Write-Host "Запускаю симулятор. Страница: http://127.0.0.1:8765" -ForegroundColor Green
|
||||
Write-Host "Это окно — движок программы: не закрывайте его, пока пользуетесь симулятором."
|
||||
Write-Host ""
|
||||
Start-Process -FilePath $VenvPyw -ArgumentList "web_proxy.py" -WorkingDirectory $Dir
|
||||
Start-Process -FilePath $VenvPyw -ArgumentList "web_proxy.py" -WorkingDirectory $Dir -WindowStyle Hidden
|
||||
Start-Process "http://127.0.0.1:8765"
|
||||
& $VenvPy web_sim.py --backend
|
||||
Reference in new issue
Block a user