后台保存debug图像
This commit is contained in:
1 parent
7b93413af7
commit
c7b5d6be0f
49 files changed
+703
-175
No files matched your search
+41
-39
@@ -577,55 +577,57 @@ class underlying_operations:
|
||||
os.remove(tmp_file)
|
||||
except Exception:
|
||||
pass
|
||||
try:
|
||||
with open(tmp_file, "wb") as f:
|
||||
subprocess.run(
|
||||
[adb, "-s", device_id, "exec-out", "screencap", "-p"],
|
||||
stdout=f,
|
||||
stderr=subprocess.DEVNULL,
|
||||
check=True,
|
||||
timeout=10, # 添加10秒超时,避免无限等待
|
||||
)
|
||||
|
||||
# 从设备获取截图(exec-out),写入临时文件
|
||||
with open(tmp_file, "wb") as f:
|
||||
subprocess.run(
|
||||
[adb, "-s", device_id, "exec-out", "screencap", "-p"],
|
||||
stdout=f,
|
||||
stderr=subprocess.DEVNULL,
|
||||
check=True,
|
||||
timeout=10, # 添加10秒超时,避免无限等待
|
||||
)
|
||||
try:
|
||||
f.flush()
|
||||
os.fsync(f.fileno())
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
if _valid_png(tmp_file):
|
||||
# 使用安全的文件替换函数
|
||||
if _safe_replace_file(tmp_file, out_file):
|
||||
_mirror_screenshot_to_external(out_file)
|
||||
# 最后再验一次目标文件,确保写入后可读
|
||||
try:
|
||||
f.flush()
|
||||
os.fsync(f.fileno())
|
||||
if _valid_png(out_file):
|
||||
print(f"[{timetag}] [截图] ✓ 获取屏幕截图成功")
|
||||
return True
|
||||
else:
|
||||
try:
|
||||
st = os.stat(out_file)
|
||||
print(f"[截图诊断] 目标文件验证失败: size={st.st_size}, mtime={st.st_mtime}")
|
||||
except Exception:
|
||||
pass
|
||||
except Exception:
|
||||
pass
|
||||
if _valid_png(tmp_file):
|
||||
# 使用安全的文件替换函数
|
||||
if _safe_replace_file(tmp_file, out_file):
|
||||
_mirror_screenshot_to_external(out_file)
|
||||
# 最后再验一次目标文件,确保写入后可读
|
||||
try:
|
||||
if _valid_png(out_file):
|
||||
print(f"[{timetag}] [截图] ✓ 获取屏幕截图成功")
|
||||
return True
|
||||
else:
|
||||
try:
|
||||
st = os.stat(out_file)
|
||||
print(f"[截图诊断] 目标文件验证失败: size={st.st_size}, mtime={st.st_mtime}")
|
||||
except Exception:
|
||||
pass
|
||||
except Exception:
|
||||
pass
|
||||
else:
|
||||
# 如果替换失败,但临时文件有效,记录诊断并重试回退方案
|
||||
try:
|
||||
if os.path.exists(tmp_file):
|
||||
st = os.stat(tmp_file)
|
||||
print(f"[截图诊断] 临时文件存在但替换失败: tmp={tmp_file}, size={st.st_size}")
|
||||
except Exception:
|
||||
pass
|
||||
# 继续尝试回退方案
|
||||
else:
|
||||
# 临时文件本身无效,记录诊断信息
|
||||
# 如果替换失败,但临时文件有效,记录诊断并重试回退方案
|
||||
try:
|
||||
if os.path.exists(tmp_file):
|
||||
st = os.stat(tmp_file)
|
||||
print(f"[截图诊断] 临时文件无效: path={tmp_file}, size={st.st_size}")
|
||||
print(f"[截图诊断] 临时文件存在但替换失败: tmp={tmp_file}, size={st.st_size}")
|
||||
except Exception:
|
||||
pass
|
||||
# 继续尝试回退方案
|
||||
else:
|
||||
# 临时文件本身无效,记录诊断信息
|
||||
try:
|
||||
if os.path.exists(tmp_file):
|
||||
st = os.stat(tmp_file)
|
||||
print(f"[截图诊断] 临时文件无效: path={tmp_file}, size={st.st_size}")
|
||||
except Exception:
|
||||
pass
|
||||
# 继续尝试回退方案
|
||||
except subprocess.TimeoutExpired:
|
||||
# 超时异常,记录并继续重试
|
||||
print(f"[截图] exec-out 超时,尝试重试或回退方案")
|
||||
|
||||
Reference in new issue
Block a user