From ec8ebafec8ba95eded1cd04078003902cf7a5c83 Mon Sep 17 00:00:00 2001 From: Pbatch <37177749+Pbatch@users.noreply.github.com> Date: Sat, 29 Jun 2024 21:51:06 +0100 Subject: [PATCH] Use shutil to get the ADB path (#189) * Use shutil to get the ADB path * Use shutil to get the ADB path --- clashroyalebuildabot/emulator/adbblitz.py | 7 ++++--- clashroyalebuildabot/emulator/emulator.py | 15 --------------- 2 files changed, 4 insertions(+), 18 deletions(-) diff --git a/clashroyalebuildabot/emulator/adbblitz.py b/clashroyalebuildabot/emulator/adbblitz.py index 47b6059..39d172c 100644 --- a/clashroyalebuildabot/emulator/adbblitz.py +++ b/clashroyalebuildabot/emulator/adbblitz.py @@ -2,6 +2,7 @@ import atexit from contextlib import contextmanager +import shutil import socket import subprocess import time @@ -33,7 +34,6 @@ class AdbShotTCP: def __init__( self, device_serial, - adb_path, max_video_width, ip="127.0.0.1", port=5555, @@ -42,7 +42,6 @@ def __init__( Args: device_serial (str): Serial number or IP address of the target device. - adb_path (str): Path to the ADB executable. ip (str, optional): IP address of the device. Defaults to "127.0.0.1". port (int, optional): Port number to connect to the device. Defaults to 5555. @@ -55,11 +54,13 @@ def __init__( __exit__(exc_type, exc_value, traceback): Context manager exit point. """ self.device_serial = device_serial - self.adb_path = adb_path self.max_video_width = max_video_width self.ip = ip self.port = port + self.adb_path = shutil.which("adb") + if self.adb_path is None: + raise ValueError("ADB is not on the PATH") self.video_socket = None self.screenshot_thread = None self.screenshot = None diff --git a/clashroyalebuildabot/emulator/emulator.py b/clashroyalebuildabot/emulator/emulator.py index afa39e3..b561968 100644 --- a/clashroyalebuildabot/emulator/emulator.py +++ b/clashroyalebuildabot/emulator/emulator.py @@ -1,5 +1,4 @@ import os -import subprocess from adb_shell.adb_device import AdbDeviceTcp from loguru import logger @@ -36,24 +35,10 @@ def __init__(self): self.blitz_device = AdbShotTCP( device_serial=serial, - adb_path=self._adb_path(), ip=ip, max_video_width=self.size[0], ) - @staticmethod - def _adb_path(): - p = subprocess.run( - ["which", "adb"], capture_output=True, text=True, check=True - ) - path = p.stdout.strip() - path = path.replace("/", "\\") - if path.startswith("\\"): - path = f"{path[1].upper()}:{path[2:]}" - path = os.path.normpath(path) - - return path - def click(self, x, y): self.device.shell(f"input tap {x} {y}")