32 lines
1.2 KiB
Python
32 lines
1.2 KiB
Python
"""宿主机无关的外部命令发现。所有平台差异只允许留在这里。"""
|
|
from __future__ import annotations
|
|
|
|
import os
|
|
import shutil
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
|
|
def adb_binary() -> str:
|
|
configured = os.environ.get("AUTOTRAIN_ADB", "").strip()
|
|
if configured:
|
|
return configured
|
|
if found := shutil.which("adb"):
|
|
return found
|
|
candidates = [
|
|
Path("/opt/homebrew/share/android-commandlinetools/platform-tools/adb"),
|
|
Path.home() / "Library/Android/sdk/platform-tools/adb",
|
|
Path(os.environ.get("LOCALAPPDATA", "")) / "Android/Sdk/platform-tools/adb.exe",
|
|
Path(os.environ.get("LOCALAPPDATA", "")) / "Android/Sdk/platform-tools/adb.exe",
|
|
Path(os.environ.get("ANDROID_HOME", "")) / "platform-tools" / ("adb.exe" if sys.platform.startswith("win") else "adb"),
|
|
Path(os.environ.get("ANDROID_SDK_ROOT", "")) / "platform-tools" / ("adb.exe" if sys.platform.startswith("win") else "adb"),
|
|
]
|
|
for candidate in candidates:
|
|
if candidate.is_file():
|
|
return str(candidate)
|
|
return "adb.exe" if sys.platform.startswith("win") else "adb"
|
|
|
|
|
|
def scrcpy_binary() -> str:
|
|
return os.environ.get("AUTOTRAIN_SCRCPY", "").strip() or (shutil.which("scrcpy") or "scrcpy")
|