Skip to content

Commit

Permalink
comments and delete useless code
Browse files Browse the repository at this point in the history
  • Loading branch information
pur1fying committed Nov 22, 2024
1 parent afa798a commit 45b57b4
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 23 deletions.
2 changes: 1 addition & 1 deletion core/color.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def check_sweep_availability(self, is_mainline=False):
return "sss"
if judgeRGBFeatureOr(self, "mainLineTaskSSS"):
return "pass"
if (self.server == "JP" or self.server == "Global") and not is_mainline :
if (self.server == "JP" or self.server == "Global") and not is_mainline:
if judgeRGBFeature(self, "sideTaskNoPass"):
return "no-pass"
if judgeRGBFeature(self, "sideTaskSSS"):
Expand Down
2 changes: 0 additions & 2 deletions core/device.py

This file was deleted.

44 changes: 27 additions & 17 deletions core/device/uiautomator2_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import requests
from uiautomator2.version import (__apk_version__, __atx_agent_version__, __jar_version__, __version__)
import os

appdir = os.path.join(os.path.expanduser("~"), '.uiautomator2')

GITHUB_BASEURL = "https://github.com/openatx"
Expand Down Expand Up @@ -46,7 +47,24 @@ def get_connection(self):
return self.connection


class BAAS_U2_Initer():
class BAAS_U2_Initer:
"""
Class to initialize uiautomator2 by following local files
src/atx_app
├── app-uiautomator.apk
├── app-uiautomator-test.apk
└── atx-agent(in different archs)
If it's your first time to use uiautomator2 (or start baas), it will initialize by downloading files from github.
It will cause following error if you can't connect to github (mainly by cn users):
HTTPSConnectionPool(host='github.com', port=443):
Max retries exceeded with url:/openatx/atx-agent/releases/download/0.10.0/atx-agent_0.10.0_linux_386_tar_gz
(Caused by NewconnectionError(': failed to establish a new connection:[winError 10061]由于目标计算机积极拒绝,无法连接。))
"""

def __init__(self, device: adbutils.AdbDevice, logger):
d = self._device = device
self.sdk = d.getprop('ro.build.version.sdk')
Expand All @@ -60,10 +78,6 @@ def __init__(self, device: adbutils.AdbDevice, logger):
# self.logger.debug("Initial device %s", device)
self.logger.info("uiautomator2 version: [ " + __version__ + " ].")

def set_atx_agent_addr(self, addr: str):
assert ":" in addr
self.__atx_listen_addr = addr

@property
def atx_agent_path(self):
return "/data/local/tmp/atx-agent"
Expand All @@ -72,20 +86,11 @@ def shell(self, *args, timeout=60):
return self._device.shell(args, timeout=timeout)

@property
def jar_urls(self):
def local_atx_agent_path(self):
"""
Returns:
iter([name, url], [name, url])
str: local atx-agent path according to device abi
"""
for name in ['bundle.jar', 'uiautomator-stub.jar']:
yield (name, "".join([
GITHUB_BASEURL,
"/android-uiautomator-jsonrpcserver/releases/download/",
__jar_version__, "/", name
]))

@property
def local_atx_agent_path(self):
files = {
'armeabi-v7a': 'atx-agent_{v}_linux_armv7/atx-agent',
'arm64-v8a': 'atx-agent_{v}_linux_arm64/atx-agent',
Expand Down Expand Up @@ -123,7 +128,8 @@ def is_apk_outdated(self):
return True
if apk_debug['version_name'] != __apk_version__:
self.logger.info(
"package com.github.uiautomator version [ " + apk_debug['version_name'] + " ] latest [ " + __apk_version__ + " ].")
"package com.github.uiautomator version [ " + apk_debug[
'version_name'] + " ] latest [ " + __apk_version__ + " ].")
return True

if apk_debug['signature'] != apk_debug_test['signature']:
Expand Down Expand Up @@ -224,6 +230,10 @@ def uninstall(self):


def app_uiautomator_apk_local_path():
"""
Returns:
List[Tuple[str, str]]: [(filename, local_path)]
"""
ret = []
for name in ["app-uiautomator.apk", "app-uiautomator-test.apk"]:
ret.append((name, "src/atx_app/" + name))
Expand Down
7 changes: 5 additions & 2 deletions core/exception.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
# import base64
import traceback
# import numpy as np


class RequestHumanTakeOver(Exception):
"""
Exception can't be handled by baas.
1. flag_run = false (click stop button)
2. unable to connect to emulator
"""
def __init__(self, message="Request Human Take Over"):
self.message = message
super().__init__(self.message)
Expand Down
1 change: 0 additions & 1 deletion core/image.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import time
import cv2
import numpy as np
from core import position, color
Expand Down
38 changes: 38 additions & 0 deletions core/position.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,47 @@
import os
import cv2

"""
This module is used to control image used by baas.
Rules:
1.Image has server,group,name,position which are stored in src/image/server/x_y_range/*.py
Example(src/image/CN/x_y_range/arena.py):
prefix = "arena" # group
path = "arena" # path of image
x_y_range = {
'menu': (107, 9, 162, 36)
'edit-force': (107, 9, 162, 36)
# name : position
}
Then put clipped screenshot image.
resource/image/server/arena
├── menu.png
└── edit-force.png
2. image group can contain " _ " character, but name must not.
Reason: get_area(server, name) use rsplit.
3. Get image
img = image_dic[server][group_name]
4. Get image area
area =
(1) image_x_y_range[server][group_name][image_name]
(2) get_area(server, group_name)
"""

image_x_y_range = {

}

image_dic = {

}

initialized_image = {
'CN': False,
'Global': False,
Expand All @@ -16,6 +51,9 @@


def init_image_data(self):
"""
param self: baas object (load image for baas.server)
"""
try:
global image_x_y_range
global image_dic
Expand Down

0 comments on commit 45b57b4

Please sign in to comment.