From ce9ad485986ceefb575982bb5224fa2f90599b5a Mon Sep 17 00:00:00 2001 From: Zhiuannnn Date: Tue, 1 Apr 2025 11:28:42 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E9=92=88=E5=AF=B9docker=E5=AE=B9=E5=99=A8?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=EF=BC=9A=201.=20=E6=8C=87=E5=AE=9Adockerfile?= =?UTF-8?q?=E4=B8=ADpython=E7=89=88=E6=9C=AC=EF=BC=8C=E9=98=B2=E6=AD=A2?= =?UTF-8?q?=E4=BD=BF=E7=94=A8python3=E9=AB=98=E7=89=88=E6=9C=AC=202.=20?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=87=AA=E5=AE=9A=E4=B9=89agent=20IP?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=EF=BC=8C=E9=98=B2=E6=AD=A2docker=20desktop?= =?UTF-8?q?=E4=B8=AD=E8=BF=90=E8=A1=8C=E8=8E=B7=E5=8F=96ip=E4=B8=BAdocker?= =?UTF-8?q?=E7=BD=91=E5=8D=A1ip=203.=20=E6=8C=87=E5=AE=9Au2=E7=89=88?= =?UTF-8?q?=E6=9C=AC=EF=BC=8C=E9=98=B2=E6=AD=A2=E4=BD=BF=E7=94=A8=E6=96=B0?= =?UTF-8?q?=E7=89=88=E5=90=A7=EF=BC=883.x.x=EF=BC=89=20Change=20for=20dock?= =?UTF-8?q?er?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 2 +- core/utils.py | 15 ++++++++++----- device.py | 12 ++++++++---- main.py | 3 +++ requirements.txt | 4 ++-- settings.py | 2 ++ 6 files changed, 26 insertions(+), 12 deletions(-) diff --git a/Dockerfile b/Dockerfile index d16d254..9520dd2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM python:3 +FROM python:3.8.10 RUN curl -sL https://deb.nodesource.com/setup_11.x | bash - RUN apt-get install -y nodejs wget diff --git a/core/utils.py b/core/utils.py index 3f1f759..27a2373 100644 --- a/core/utils.py +++ b/core/utils.py @@ -6,14 +6,19 @@ import re import socket import string +import settings + def current_ip(): - s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) - s.connect(("8.8.8.8", 80)) - ip = s.getsockname()[0] - s.close() - return ip + if settings.custom_agent_ip != "none": + return settings.custom_agent_ip + else: + s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) + s.connect(("8.8.8.8", 80)) + ip = s.getsockname()[0] + s.close() + return ip def update_recursive(d: dict, u: dict) -> dict: diff --git a/device.py b/device.py index 59190c8..322432a 100644 --- a/device.py +++ b/device.py @@ -146,13 +146,17 @@ def _install_apk(self, path: str): try: m = apkutils.APK(path).manifest info = self._device.package_info(m.package_name) - if info and m.version_code == info[ - 'version_code'] and m.version_name == info['version_name']: + if info and str(m.version_code) == str(info[ + 'version_code']) and m.version_name == info['version_name']: logger.debug("%s already installed %s", self, path) + elif info and info['version_name'] == None : + logger.debug(f"{info}, : {m.version_code}, {m.version_name}") + logger.debug("Unable to get apk version,skip to install") + return else: - print(info, ":", m.version_code, m.version_name) + logger.debug(f"{info}, : {m.version_code}, {m.version_name}") logger.debug("%s install %s", self, path) - self._device.install(path, force=True) + self._device.install(path) except Exception as e: traceback.print_exc() logger.warning("%s Install apk %s error %s", self, path, e) diff --git a/main.py b/main.py index c93db2a..6361e65 100755 --- a/main.py +++ b/main.py @@ -287,10 +287,12 @@ async def async_main(): parser.add_argument("--atx-agent-version", default=u2.version.__atx_agent_version__, help="set atx-agent version") parser.add_argument("--owner", type=str, help="provider owner email") parser.add_argument("--owner-file", type=argparse.FileType("r"), help="provider owner email from file") + parser.add_argument("--custom-agent-ip", default='none', help="custom agent ip address") args = parser.parse_args() # yapf: enable settings.atx_agent_version = args.atx_agent_version + settings.custom_agent_ip = args.custom_agent_ip owner_email = args.owner if args.owner_file: @@ -307,6 +309,7 @@ async def async_main(): logger.info("Ret: %s", ret) return + # start local server provider_url = "http://" + current_ip() + ":" + str(args.port) app = make_app() diff --git a/requirements.txt b/requirements.txt index f29c705..6221619 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,7 @@ logzero==1.5.* -adbutils>=0.8.1,<1.0 +adbutils==2.8.5 tornado requests apkutils2 -uiautomator2>=2.5.9 +uiautomator2==2.16.26 humanize diff --git a/settings.py b/settings.py index d939dee..3f2fc55 100644 --- a/settings.py +++ b/settings.py @@ -2,3 +2,5 @@ # atx_agent_version = "" # set from command line + +custom_agent_ip = "" # set from command line From 8d8e64915c47ad755b8af8e1653b32b431c1b479 Mon Sep 17 00:00:00 2001 From: zhiuannnn Date: Wed, 2 Apr 2025 09:42:46 +0800 Subject: [PATCH 2/2] =?UTF-8?q?STF=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/fetching.py | 2 +- device.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/core/fetching.py b/core/fetching.py index 553a7f6..8f1b409 100644 --- a/core/fetching.py +++ b/core/fetching.py @@ -59,7 +59,7 @@ def get_stf_binaries() -> str: Tag 0.2, support to Android P Tag 0.3.0 use stf/@devicefarmer """ - version = "0.3.0" + version = "0.3.2" target_path = f"vendor/stf-binaries-{version}.zip" mirror_download( f"https://github.com/openatx/stf-binaries/archive/{version}.zip", diff --git a/device.py b/device.py index 322432a..5b5404d 100644 --- a/device.py +++ b/device.py @@ -86,7 +86,7 @@ def _init_binaries(self): stf_zippath = fetching.get_stf_binaries() zip_folder, _ = os.path.splitext(os.path.basename(stf_zippath)) - prefix = zip_folder + "/node_modules/@devicefarmer/minicap-prebuilt/prebuilt/" + prefix = zip_folder + "/node_modules/minicap-prebuilt/prebuilt/" self._push_stf(prefix + abi + "/lib/android-" + sdk + "/minicap.so", "/data/local/tmp/minicap.so", mode=0o644,