20250904-初步功能已完成
This commit is contained in:
@@ -253,16 +253,15 @@ class AiUtils(object):
|
||||
# 查找发消息按钮
|
||||
@classmethod
|
||||
def getSendMesageButton(cls, session: Client):
|
||||
# msgButton = session.xpath("//Window[1]/Other[1]/Other[1]/Other[1]/Other[1]/Other[1]/Other[1]/Other[1]/Other[1]/Other[1]/Other[2]/Other[2]/Other[1]/Other[1]/Other[3]/Other[1]/Other[1]")
|
||||
|
||||
# msgButton = session.xpath(
|
||||
# '//XCUIElementTypeButton[@name="发消息" or @label="发消息"]')
|
||||
|
||||
msgButton = session.xpath(
|
||||
'//XCUIElementTypeButton['
|
||||
'(@name="发消息" or @label="发消息" or @name="发送 👋" or @label="发送 👋")'
|
||||
'(@name="发消息" or @label="发消息" or '
|
||||
'@name="发送 👋" or @label="发送 👋" or '
|
||||
'@name="消息" or @label="消息")'
|
||||
' and @visible="true"]'
|
||||
)
|
||||
|
||||
if msgButton.exists:
|
||||
print("3.发消息按钮找到了")
|
||||
LogManager.info("3.发消息按钮找到了")
|
||||
|
||||
@@ -80,18 +80,19 @@
|
||||
# shutil.rmtree(item)
|
||||
#
|
||||
# print("日志清空完成")
|
||||
|
||||
|
||||
import datetime
|
||||
import io
|
||||
import logging
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
import shutil
|
||||
import zipfile
|
||||
from pathlib import Path
|
||||
|
||||
import requests
|
||||
|
||||
from Entity.Variables import token
|
||||
import Entity.Variables
|
||||
|
||||
|
||||
class LogManager:
|
||||
@@ -260,52 +261,45 @@ class LogManager:
|
||||
print("日志清空完成")
|
||||
|
||||
@classmethod
|
||||
def upload_all_logs(cls, server_url: str, extra_data: dict = None):
|
||||
"""
|
||||
上传 log/ 目录下所有文件和子目录中的日志
|
||||
"""
|
||||
def upload_all_logs(cls, server_url, token, userId, tenantId):
|
||||
log_path = Path(cls.logDir)
|
||||
if not log_path.exists():
|
||||
print("[upload_all_logs] 日志目录不存在")
|
||||
return False
|
||||
|
||||
success_files, failed_files = [], []
|
||||
timestamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
|
||||
filename = f"{timestamp}_logs.zip"
|
||||
|
||||
for file in log_path.rglob("*.log"): # 递归找到所有 .log 文件
|
||||
try:
|
||||
zip_buf = io.BytesIO()
|
||||
with zipfile.ZipFile(zip_buf, "w", compression=zipfile.ZIP_DEFLATED) as zf:
|
||||
for p in log_path.rglob("*"):
|
||||
if p.is_file():
|
||||
arcname = str(p.relative_to(log_path))
|
||||
zf.write(p, arcname=arcname)
|
||||
|
||||
files = {"file": open(file, "rb")}
|
||||
headers = {
|
||||
"Authorization": f"Bearer {token}",
|
||||
}
|
||||
zip_bytes = zip_buf.getvalue()
|
||||
|
||||
data = {
|
||||
# "relative_path": str(file.relative_to(log_path))
|
||||
"tenantId": 1,
|
||||
"userId": 1,
|
||||
}
|
||||
headers = {"vvtoken": token}
|
||||
data = {"tenantId": tenantId, "userId": userId}
|
||||
|
||||
if extra_data:
|
||||
data.update(extra_data)
|
||||
resp = requests.post(server_url, files=files, data=data, headers=headers ,timeout=15)
|
||||
|
||||
print(resp.text)
|
||||
print(resp.status_code)
|
||||
files = {
|
||||
"file": (filename, io.BytesIO(zip_bytes), "application/zip")
|
||||
}
|
||||
print(
|
||||
f"[upload_all_logs] "
|
||||
f"server={server_url} (type={type(server_url)}) "
|
||||
f"tenantId={tenantId} (type={type(tenantId)}) "
|
||||
f"userId={userId} (type={type(userId)}) "
|
||||
f"token={token} (type={type(token)})"
|
||||
)
|
||||
|
||||
if resp.status_code == 200:
|
||||
success_files.append(file.name)
|
||||
else:
|
||||
failed_files.append((file.name, resp.status_code))
|
||||
except Exception as e:
|
||||
failed_files.append((file.name, str(e)))
|
||||
finally:
|
||||
try:
|
||||
files["file"].close()
|
||||
except:
|
||||
pass
|
||||
print("开始上传")
|
||||
# 3) 上传
|
||||
resp = requests.post(server_url, headers=headers, data=data, files=files)
|
||||
print(resp.text)
|
||||
print("上传结束")
|
||||
|
||||
print(f"[upload_all_logs] 成功上传: {success_files}")
|
||||
if failed_files:
|
||||
print(f"[upload_all_logs] 失败文件: {failed_files}")
|
||||
|
||||
return len(failed_files) == 0
|
||||
if resp.json()['data']:
|
||||
return True
|
||||
return False
|
||||
|
||||
Reference in New Issue
Block a user