1. actions.py 2.add_trasition.py 3.check_upload.py

This commit is contained in:
2026-06-09 14:52:29 +08:00
parent 1e17816a89
commit de5173ded6
14 changed files with 1208 additions and 359 deletions

View File

@@ -1,7 +1,9 @@
import logging
import os
import sys
import time
import subprocess
import argparse
from tkinter import E
from appium import webdriver
from appium.options.android import UiAutomator2Options
@@ -143,8 +145,14 @@ class DeviceAutomation:
logging.error(f"设备 {self.device_id} 初始化驱动失败: {str(e)}")
raise
def run_automation(self):
"""根据当前应用状态处理相应的操作"""
def run_automation(self, task_data=None):
"""根据当前应用状态处理相应的操作
Args:
task_data: 可选的任务数据字典,包含 user_name, line_name, line_num, id 等字段。
如果传入,则使用传入值设置全局变量;
如果不传,则使用硬编码的默认值。
"""
try:
max_retry = 3 # 限制最大重试次数
retry_count = 0
@@ -193,19 +201,21 @@ class DeviceAutomation:
task_count = 0
# 获取测量任务
logging.info(f"设备 {self.device_id} 获取测量任务 (第{task_count + 1}次)")
# task_data = apis.get_measurement_task()
# logging.info(f"设备 {self.device_id} 获取到的测量任务: {task_data}")
task_data = {
"id": 21,
"user_name": "czsczq115ykl",
"name": "czsczq115ykl",
"line_num": "L220076",
"line_name": "CZSCZQ-11-五工区-列衣隧道进口-D3K638+507-D3K638+607-山区",
"remaining": "0",
"status": 0
}
# 获取测量任务:优先使用传入的 task_data否则使用硬编码默认值
if task_data is None:
logging.info(f"设备 {self.device_id} 获取测量任务 (第{task_count + 1}次)")
# task_data = apis.get_measurement_task()
# logging.info(f"设备 {self.device_id} 获取到的测量任务: {task_data}")
task_data = {
"id": 21,
"user_name": "czsczq115ykl",
"name": "czsczq115ykl",
"line_num": "L220179",
"line_name": "CZSCZQ-11-五工区-德达隧道6#斜井左线-DK632+707-DK632+705-山区",
"remaining": "0",
"status": 0
}
if not task_data:
logging.info(f"设备 {self.device_id} 未获取到状态为1的测量任务等待后重试")
time.sleep(1) # 等待1秒后重试
@@ -264,6 +274,14 @@ class DeviceAutomation:
# 主执行逻辑
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='DeviceAutomation 脚本 - 执行设备自动化流程')
parser.add_argument('--user_name', type=str, default='', help='用户名')
parser.add_argument('--line_name', type=str, default='', help='项目/线路名称')
parser.add_argument('--line_num', type=str, default='', help='线路编码')
parser.add_argument('--account_id', type=int, default=0, help='账号ID')
args = parser.parse_args()
device_id = create_link.setup_adb_wireless()
automation = None
try:
@@ -271,12 +289,27 @@ if __name__ == "__main__":
logging.error("未能获取设备 ID无法继续执行自动化流程")
else:
automation = DeviceAutomation(device_id=device_id)
success = automation.run_automation()
# 如果传入了命令行参数,则构建 task_data 并传入
if args.user_name or args.line_name or args.line_num or args.account_id:
task_data = {
"id": args.account_id,
"user_name": args.user_name,
"line_num": args.line_num,
"line_name": args.line_name,
}
logging.info(f"使用命令行参数: {task_data}")
success = automation.run_automation(task_data=task_data)
else:
logging.info("未传入命令行参数,使用默认 task_data")
success = automation.run_automation()
if success:
logging.info(f"设备 {automation.device_id} 自动化流程执行成功")
print("自动化流程执行成功")
else:
logging.error(f"设备 {automation.device_id} 自动化流程执行失败")
print("自动化流程执行失败")
# 保持脚本运行,不关闭连接
logging.info("自动化流程执行完成,保持连接状态...")