20250904-初步功能已完成
This commit is contained in:
@@ -1,11 +1,16 @@
|
||||
import json
|
||||
import os
|
||||
import shlex
|
||||
import subprocess
|
||||
import time
|
||||
from pathlib import Path
|
||||
|
||||
import cv2
|
||||
import numpy as np
|
||||
import unicodedata
|
||||
import wda
|
||||
|
||||
from Entity.Variables import WdaAppBundleId
|
||||
from Utils.LogManager import LogManager
|
||||
import xml.etree.ElementTree as ET
|
||||
import re, html
|
||||
@@ -709,4 +714,72 @@ class AiUtils(object):
|
||||
json.dump(data, f, ensure_ascii=False, indent=2)
|
||||
except Exception as e:
|
||||
LogManager.error(f"[delete_anchors_by_ids] 写入失败: {e}")
|
||||
return deleted
|
||||
return deleted
|
||||
|
||||
@staticmethod
|
||||
def run_tidevice_command(udid, action, bundle_id, timeout=30):
|
||||
"""
|
||||
执行tidevice命令的辅助函数
|
||||
|
||||
:param udid: 设备UDID
|
||||
:param action: 动作类型 ('kill' 或 'launch')
|
||||
:param bundle_id: 应用的Bundle ID
|
||||
:param timeout: 命令执行超时时间(秒)
|
||||
:return: (bool) 成功返回True,失败返回False
|
||||
"""
|
||||
# 构建命令列表
|
||||
cmd = ["tidevice", "--udid", udid, action, bundle_id]
|
||||
try:
|
||||
# 执行命令并捕获输出
|
||||
result = subprocess.run(
|
||||
cmd,
|
||||
capture_output=True,
|
||||
text=True,
|
||||
timeout=timeout
|
||||
)
|
||||
# 检查命令是否成功执行(返回码为0通常表示成功)
|
||||
if result.returncode == 0:
|
||||
LogManager.info(f"Successfully {action}ed {bundle_id} on device {udid}.")
|
||||
return True
|
||||
else:
|
||||
# 记录错误信息
|
||||
LogManager.error(f"Failed to {action} {bundle_id} on device {udid}. Error: {result.stderr}")
|
||||
return False
|
||||
|
||||
except subprocess.TimeoutExpired:
|
||||
# 处理命令执行超时
|
||||
LogManager.error(f"Command 'tidevice {action}' timed out after {timeout} seconds for device {udid}.")
|
||||
return False
|
||||
except FileNotFoundError:
|
||||
# 处理tidevice命令未找到的情况(通常意味着tidevice未安装或不在PATH中)
|
||||
LogManager.error("The 'tidevice' command was not found. Please ensure it is installed and in your system PATH.")
|
||||
return False
|
||||
except Exception as e:
|
||||
# 捕获其他可能异常
|
||||
LogManager.error(f"An unexpected error occurred while trying to {action} the app: {e}")
|
||||
return False
|
||||
|
||||
@classmethod
|
||||
def kill_wda(cls, udid, bundle_id="com.yolozsAgent.wda.xctrunner"):
|
||||
"""
|
||||
杀死指定设备上的WDA应用
|
||||
|
||||
:param udid: 设备UDID
|
||||
:param bundle_id: WDA的Bundle ID,默认为 com.yolozsAgent.wda.xctrunner
|
||||
:return: (bool) 成功返回True,失败返回False
|
||||
"""
|
||||
return cls.run_tidevice_command(udid, "kill", bundle_id)
|
||||
|
||||
@classmethod
|
||||
def launch_wda(cls, udid, bundle_id="com.yolozsAgent.wda.xctrunner", timeout=60):
|
||||
"""
|
||||
启动指定设备上的WDA应用
|
||||
|
||||
:param udid: 设备UDID
|
||||
:param bundle_id: WDA的Bundle ID,默认为 com.yolozsAgent.wda.xctrunner
|
||||
:param timeout: 启动命令超时时间,默认为60秒(启动可能较慢)
|
||||
:return: (bool) 成功返回True,失败返回False
|
||||
"""
|
||||
return cls.run_tidevice_command(udid, "launch", bundle_id, timeout)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user