调整日志
This commit is contained in:
3
.idea/workspace.xml
generated
3
.idea/workspace.xml
generated
@@ -6,9 +6,8 @@
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="eceeff5e-51c1-459c-a911-d21ec090a423" name="Changes" comment="20250904-初步功能已完成">
|
||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/Entity/DeviceModel.py" beforeDir="false" afterPath="$PROJECT_DIR$/Entity/DeviceModel.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/Module/DeviceInfo.py" beforeDir="false" afterPath="$PROJECT_DIR$/Module/DeviceInfo.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/Utils/LogManager.py" beforeDir="false" afterPath="$PROJECT_DIR$/Utils/LogManager.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/Utils/ControlUtils.py" beforeDir="false" afterPath="$PROJECT_DIR$/Utils/ControlUtils.py" afterDir="false" />
|
||||
</list>
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||
|
||||
@@ -180,47 +180,58 @@ class Deviceinfo(object):
|
||||
self.manager.send(model.toDict())
|
||||
except Exception as e:
|
||||
LogManager.warning(f"{model.deviceId} 发送上线事件失败:{e}")
|
||||
LogManager.info(f"{model.deviceId} 设备上线,当前在线数:{len(self.deviceModelList)}")
|
||||
LogManager.method_info(f"{model.deviceId} 加入设备成功,当前在线数:{len(self.deviceModelList)}",method="device_count")
|
||||
|
||||
|
||||
# 删除设备
|
||||
def _remove_model(self, udid: str):
|
||||
print(f"【删】进入删除方法 udid={udid}")
|
||||
LogManager.method_info(f"【删】进入删除方法 udid={udid}", method="device_count")
|
||||
# 1. 纯内存临界区——毫秒级
|
||||
with self._lock:
|
||||
print(f"【删】拿到锁 udid={udid}")
|
||||
LogManager.method_info(f"【删】拿到锁 udid={udid}",
|
||||
method="device_count")
|
||||
model = self._model_index.pop(udid, None)
|
||||
if not model:
|
||||
print(f"【删】模型已空,直接返回 udid={udid}")
|
||||
LogManager.method_info(f"【删】模型已空,直接返回 udid={udid}",method="device_count")
|
||||
return
|
||||
if model.deleting:
|
||||
print(f"【删】正在删除中,幂等返回 udid={udid}")
|
||||
LogManager.method_info(method="device_count", text=f"【删】正在删除中,幂等返回 udid={udid}")
|
||||
return
|
||||
model.deleting = True
|
||||
# 标记维删除设备
|
||||
model.type = 2
|
||||
print(f"【删】标记 deleting=True udid={udid}")
|
||||
|
||||
LogManager.method_info("【删】标记 deleting=True udid={udid}","device_count")
|
||||
# 过滤列表
|
||||
before = len(self.deviceModelList)
|
||||
self.deviceModelList = [m for m in self.deviceModelList if m.deviceId != udid]
|
||||
after = len(self.deviceModelList)
|
||||
print(f"【删】列表过滤 before={before} → after={after} udid={udid}")
|
||||
LogManager.method_info(f"【删】列表过滤 before={before} → after={after} udid={udid}","device_count")
|
||||
|
||||
# 端口
|
||||
self._port_in_use.discard(model.screenPort)
|
||||
self._port_pool.append(model.screenPort)
|
||||
print(f"【删】回收端口 port={model.screenPort} udid={udid}")
|
||||
LogManager.method_info(f"【删】回收端口 port={model.screenPort} udid={udid}", method="device_count")
|
||||
|
||||
# 进程
|
||||
to_kill = [item for item in self.pidList if item.get("id") == udid]
|
||||
self.pidList = [item for item in self.pidList if item.get("id") != udid]
|
||||
print(f"【删】待杀进程数 count={len(to_kill)} udid={udid}")
|
||||
LogManager.method_info(f"【删】待杀进程数 count={len(to_kill)} udid={udid}", method="device_count")
|
||||
|
||||
# 2. IO 区无锁
|
||||
for idx, item in enumerate(to_kill, 1):
|
||||
print(f"【删】杀进程 {idx}/{len(to_kill)} pid={item.get('target').pid} udid={udid}")
|
||||
LogManager.method_error(f"【删】杀进程 {idx}/{len(to_kill)} pid={item.get('target').pid} udid={udid}", method="device_count")
|
||||
self._terminate_proc(item.get("target"))
|
||||
print(f"【删】进程清理完成 udid={udid}")
|
||||
LogManager.method_info(f"【删】进程清理完成 udid={udid}", method="device_count")
|
||||
|
||||
# 3. 网络 IO
|
||||
retry = 3
|
||||
@@ -228,18 +239,21 @@ class Deviceinfo(object):
|
||||
try:
|
||||
self.manager.send(model.toDict())
|
||||
print(f"【删】下线事件已发送 udid={udid}")
|
||||
LogManager.method_info(f"【删】下线事件已发送 udid={udid}", method="device_count")
|
||||
break
|
||||
except Exception as e:
|
||||
retry -= 1
|
||||
print(f"【删】发送事件失败 retry={retry} err={e} udid={udid}")
|
||||
LogManager.method_error(f"【删】发送事件失败 retry={retry} err={e} udid={udid}", method="device_count")
|
||||
time.sleep(0.2)
|
||||
else:
|
||||
print(f"【删】发送事件彻底失败,主动退出 udid={udid}")
|
||||
os._exit(1)
|
||||
LogManager.method_error(f"【删】发送事件彻底失败,主动退出 udid={udid}", method="device_count")
|
||||
|
||||
print(f"【删】===== 设备 {udid} 删除全流程结束 =====")
|
||||
LogManager.method_info(f"【删】===== 设备 {udid} 删除全流程结束 =====", method="device_count")
|
||||
print(len(self.deviceModelList))
|
||||
|
||||
LogManager.method_info(f"当前剩余设备数量:{len(self.deviceModelList)}", method="device_count")
|
||||
|
||||
# region ===================== 端口分配与回收 =====================
|
||||
def _alloc_port(self) -> int:
|
||||
@@ -295,8 +309,6 @@ class Deviceinfo(object):
|
||||
if target:
|
||||
self.pidList.append({"target": target, "id": udid})
|
||||
|
||||
# endregion
|
||||
|
||||
# region ===================== 工具方法 =====================
|
||||
def is_device_trusted(self, udid: str) -> bool:
|
||||
try:
|
||||
|
||||
@@ -182,22 +182,8 @@ class ControlUtils(object):
|
||||
# 点击一个随机范围
|
||||
@classmethod
|
||||
def tap_mini_cluster(cls, center_x: int, center_y: int, session, points=5, duration_ms=60):
|
||||
"""
|
||||
以 (center_x, center_y) 为中心,在 3×3 像素范围内摆 `points` 个邻近坐标,
|
||||
一次性同时按下,持续 `duration_ms` 后抬起。
|
||||
"""
|
||||
# 1. 生成邻像素坐标(±1 像素内)
|
||||
cluster = []
|
||||
for i in range(points):
|
||||
dx = random.randint(-1, 1)
|
||||
dy = random.randint(-1, 1)
|
||||
cluster.append((center_x + dx, center_y + dy))
|
||||
pass
|
||||
|
||||
# 2. 随机持续时间 50–100 ms
|
||||
duration_s = random.randint(50, 100) / 1000.0
|
||||
|
||||
# 3. 下发多点触控
|
||||
session.tap_hold_coords(cluster, duration=duration_s)
|
||||
# 检测五分钟前和当前的状态是否相同
|
||||
# @classmethod
|
||||
# def compareCurrentWithPreviousState(cls,xml):
|
||||
|
||||
Reference in New Issue
Block a user