Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use shutil to get the ADB path #189

Merged
merged 2 commits into from
Jun 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions clashroyalebuildabot/emulator/adbblitz.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import atexit
from contextlib import contextmanager
import shutil
import socket
import subprocess
import time
Expand Down Expand Up @@ -33,7 +34,6 @@ class AdbShotTCP:
def __init__(
self,
device_serial,
adb_path,
max_video_width,
ip="127.0.0.1",
port=5555,
Expand All @@ -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.

Expand All @@ -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
Expand Down
15 changes: 0 additions & 15 deletions clashroyalebuildabot/emulator/emulator.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import os
import subprocess

from adb_shell.adb_device import AdbDeviceTcp
from loguru import logger
Expand Down Expand Up @@ -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}")

Expand Down