chore: 初始化仓库(排除 adb 二进制文件以解决推送超时)

This commit is contained in:
2026-08-07 13:55:48 +08:00
commit bce48fc137
35 changed files with 6301 additions and 0 deletions
+1
View File
@@ -0,0 +1 @@
"""scripts 包:实用脚本(清理、批量操作等)。每个脚本可独立运行。"""
+49
View File
@@ -0,0 +1,49 @@
"""清理 STF 上残留的设备占用(强杀进程导致没正常释放时用)。
运行:python scripts/cleanup.py
(在 auto/ 目录下运行也可:python -m scripts.cleanup)
"""
import os
import sys
# 让脚本既能直接运行(python scripts/cleanup.py)又能作为模块运行。
# scripts/ 的上一级 auto/ 是 core 包的父目录,需加入 sys.path。
_AUTO_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
if _AUTO_DIR not in sys.path:
sys.path.insert(0, _AUTO_DIR)
import requests
from config import STF_URL, STF_TOKEN
headers = {"Authorization": f"Bearer {STF_TOKEN}"}
# /user/devices 返回当前用户正在占用的设备
resp = requests.get(f"{STF_URL}/api/v1/user/devices", headers=headers)
resp.raise_for_status()
data = resp.json()
mine = data.get("devices", [])
print(f"当前账户占用的设备数: {len(mine)}")
for d in mine:
print(f" - {d.get('serial')} using={d.get('using')}")
# 全部释放
for d in mine:
serial = d["serial"]
try:
requests.post(
f"{STF_URL}/api/v1/user/devices/{serial}/remoteDisconnect",
headers=headers,
)
except Exception:
pass
r = requests.delete(f"{STF_URL}/api/v1/user/devices/{serial}", headers=headers)
print(f"释放 {serial}: HTTP {r.status_code}")
# 再看一次总设备池
resp = requests.get(f"{STF_URL}/api/v1/devices", headers=headers)
resp.raise_for_status()
free = [d for d in resp.json().get("devices", [])
if d.get("present") and d.get("ready") and not d.get("using") and d.get("owner") is None]
print(f"\n清理后空闲设备数: {len(free)}")
for d in free:
print(f" - {d.get('serial')}")
+57
View File
@@ -0,0 +1,57 @@
@echo off
title Fix Web Access
:: Auto elevate to admin
net session >nul 2>&1
if %errorLevel% neq 0 (
echo Requesting admin privileges...
powershell -Command "Start-Process cmd -ArgumentList '/c ""%~f0""' -Verb RunAs"
exit /b
)
echo ============================================
echo Fix Web Backend Access
echo ============================================
echo.
:: 1. Disable residual system proxy (blocks localhost)
echo [1/4] Disabling system proxy...
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyEnable /t REG_DWORD /d 0 /f >nul 2>&1
reg delete "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyServer /f >nul 2>&1
echo Done.
echo.
:: 2. Add firewall rules for Python
echo [2/4] Adding firewall rules for Python...
for /f "delims=" %%i in ('where python') do set PYTHON_PATH=%%i
if not defined PYTHON_PATH (
echo ERROR: Python not found in PATH
pause
exit /b 1
)
echo Python path: %PYTHON_PATH%
netsh advfirewall firewall delete rule name="PythonWeb" >nul 2>&1
netsh advfirewall firewall add rule name="PythonWeb" dir=in action=allow program="%PYTHON_PATH%" enable=yes profile=any >nul
netsh advfirewall firewall delete rule name="PythonWebOut" >nul 2>&1
netsh advfirewall firewall add rule name="PythonWebOut" dir=out action=allow program="%PYTHON_PATH%" enable=yes profile=any >nul
echo Done.
echo.
:: 3. Flush DNS cache
echo [3/4] Flushing DNS cache...
ipconfig /flushdns >nul 2>&1
echo Done.
echo.
:: 4. Show excluded port ranges for reference
echo [4/4] TCP excluded port ranges (for reference):
netsh interface ipv4 show excludedportrange protocol=tcp
echo.
echo ============================================
echo Fix complete! Now:
echo 1. Close ALL browser windows and reopen
echo 2. Run: python web_server.py
echo 3. Open: http://127.0.0.1:5050/
echo ============================================
pause
+67
View File
@@ -0,0 +1,67 @@
"""打包脚本:把项目代码打成 zip 压缩包,排除运行时产物。
用法:python scripts/pack.py
输出:项目根目录下 platform-tools.zip
"""
import os
import sys
import zipfile
ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
OUT = os.path.join(os.path.dirname(ROOT), "platform-tools.zip")
SKIP_DIRS = {"__pycache__", ".git", ".idea", "venv", ".venv", "node_modules"}
SKIP_EXTS = {".pyc", ".pyo"}
# 路径片段包含这些的跳过
SKIP_PARTS = {"__pycache__"}
# 文件名完全匹配这些的跳过
SKIP_FILES = {"fix_web.bat"}
# 文件名后缀匹配这些的跳过
SKIP_SUFFIX = (".migrated",)
# 特定目录下特定后缀跳过
# logs/ 下的 .log
# data/apks/ 下的 .apk
def should_skip(path, name):
full = os.path.join(path, name)
rel = os.path.relpath(full, ROOT)
norm = rel.replace("\\", "/")
if "__pycache__" in norm:
return True
if name in SKIP_FILES:
return True
if name.endswith(SKIP_SUFFIX):
return True
ext = os.path.splitext(name)[1]
if ext in SKIP_EXTS:
return True
if name.endswith(".log") and "/logs/" in norm:
return True
if name.endswith(".apk") and "/data/apks/" in norm:
return True
return False
def main():
if os.path.exists(OUT):
os.remove(OUT)
count = 0
with zipfile.ZipFile(OUT, "w", zipfile.ZIP_DEFLATED) as z:
for dp, dn, fn in os.walk(ROOT):
# 原地修改 dn 跳过目录
dn[:] = [d for d in dn if d not in SKIP_DIRS]
for f in fn:
if should_skip(dp, f):
continue
full = os.path.join(dp, f)
arc = os.path.relpath(full, os.path.dirname(ROOT))
z.write(full, arc)
count += 1
size_kb = os.path.getsize(OUT) // 1024
print(f"打包完成: {OUT}")
print(f"文件数: {count}, 大小: {size_kb} KB ({size_kb/1024:.1f} MB)")
if __name__ == "__main__":
main()