mirror of
https://gitee.com/gfdgd-xi/deep-wine-runner
synced 2025-12-13 18:42:03 +08:00
Have finished log report maker
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#!/usr/bin/env python3
|
||||
# 读取设置单独用一个 py 文件
|
||||
import os
|
||||
import sys
|
||||
import json
|
||||
import base64
|
||||
import shutil
|
||||
@@ -8,7 +9,10 @@ import getpass
|
||||
import datetime
|
||||
import traceback
|
||||
import subprocess
|
||||
import configparser
|
||||
import PyQt5.QtGui as QtGui
|
||||
import PyQt5.QtCore as QtCore
|
||||
import PyQt5.QtWidgets as QtWidgets
|
||||
|
||||
# 获取用户主目录
|
||||
def get_home():
|
||||
@@ -43,6 +47,7 @@ defultProgramList = {
|
||||
}
|
||||
|
||||
programPath = os.path.split(os.path.realpath(__file__))[0] # 返回 string
|
||||
iconPath = "{}/deepin-wine-runner.svg".format(programPath)
|
||||
try:
|
||||
setting = json.loads(readtxt(get_home() + "/.config/deepin-wine-runner/WineSetting.json"))
|
||||
information = json.loads(readtxt(f"{programPath}/information.json"))
|
||||
@@ -92,7 +97,10 @@ def FileToBase64(filePath):
|
||||
src += base64Byte.decode("utf-8")
|
||||
return src
|
||||
|
||||
class SaveLog():
|
||||
def SaveLogWindow():
|
||||
pass
|
||||
|
||||
class SaveLogReport():
|
||||
userName = getpass.getuser()
|
||||
time = datetime.datetime.now().strftime("%Y/%m/%d %H:%M:%S")
|
||||
kernelVersion = subprocess.getoutput("uname -a")
|
||||
@@ -103,9 +111,8 @@ class SaveLog():
|
||||
lshw = subprocess.getoutput("lshw")
|
||||
cpu = subprocess.getoutput("cat /proc/cpuinfo | grep 'model name' | head -n 1 | awk -F: '{print $2}'")
|
||||
gpu = subprocess.getoutput("lspci | grep -i 'VGA\|3D\|2D'")
|
||||
|
||||
|
||||
def __init__(self, chooseWineName, chooseWineCommand, runCommand, binPath, logOut, description, imgPath=[]) -> None:
|
||||
def __init__(self, chooseWineName, chooseWineCommand, runCommand, binPath, logOut, description="无", imgPath=[]) -> None:
|
||||
self.chooseWineName = chooseWineName
|
||||
self.chooseWineCommand = chooseWineCommand
|
||||
self.runCommand = runCommand
|
||||
@@ -138,12 +145,104 @@ class SaveLog():
|
||||
except:
|
||||
traceback.print_exc()
|
||||
self.memoryInfo = traceback.format_exc()
|
||||
# 读取系统信息
|
||||
try:
|
||||
with open("/etc/os-release", "r") as file:
|
||||
text = "[Default]\n" + file.read()
|
||||
conf = configparser.ConfigParser()
|
||||
conf.read_string(text)
|
||||
self.systemVersion = conf.get("Default", "PRETTY_NAME")
|
||||
except:
|
||||
traceback.print_exc()
|
||||
self.systemVersion = subprocess.getoutput("lsb_release -a")
|
||||
|
||||
def SetWindow(self):
|
||||
def AddImageToListClicked():
|
||||
choose = QtWidgets.QFileDialog.getOpenFileNames(messagebox, "选择图像", get_home(), "图片文件(*.png *.jpg *.bmp *.gif *.svg);;所有文件(*.*)")
|
||||
print(choose)
|
||||
for i in choose[0]:
|
||||
if i in imageList:
|
||||
continue
|
||||
imageList.append(i)
|
||||
nmodel = QtGui.QStandardItemModel(messagebox)
|
||||
for i in imageList:
|
||||
item = QtGui.QStandardItem(i)
|
||||
nmodel.appendRow(item)
|
||||
imageListView.setModel(nmodel)
|
||||
|
||||
def DeleteImageToListClicked():
|
||||
index = imageListView.currentIndex().row()
|
||||
if index < 0:
|
||||
QtWidgets.QMessageBox.information(messagebox, "提示", "您未选择任何项")
|
||||
return
|
||||
del imageList[index]
|
||||
nmodel = QtGui.QStandardItemModel(messagebox)
|
||||
for i in imageList:
|
||||
item = QtGui.QStandardItem(i)
|
||||
nmodel.appendRow(item)
|
||||
imageListView.setModel(nmodel)
|
||||
# 选择第一项
|
||||
imageListView.setCurrentIndex(nmodel.index(0, 0))
|
||||
|
||||
def OkClicked():
|
||||
self.description = description.toPlainText()
|
||||
self.imgPath = imageList
|
||||
path = QtWidgets.QFileDialog.getSaveFileName(messagebox, "保存日志报告", get_home(), "7z 文件(*.7z);;所有文件(*.*)")
|
||||
print(path)
|
||||
if path[0] != "":
|
||||
try:
|
||||
self.To7z(path[0])
|
||||
except:
|
||||
traceback.print_exc()
|
||||
QtWidgets.QMessageBox.critical(messagebox, "错误", traceback.format_exc())
|
||||
return
|
||||
messagebox.close()
|
||||
QtWidgets.QMessageBox.information(messagebox, "提示", "生成完成!")
|
||||
|
||||
def CancelClicked():
|
||||
messagebox.close()
|
||||
|
||||
# 权重
|
||||
size = QtWidgets.QSizePolicy()
|
||||
size.setHorizontalPolicy(0)
|
||||
imageList = []
|
||||
messagebox = QtWidgets.QDialog()
|
||||
layout = QtWidgets.QGridLayout()
|
||||
description = QtWidgets.QTextEdit()
|
||||
imageListView = QtWidgets.QListView()
|
||||
addImageToList = QtWidgets.QPushButton("+")
|
||||
deleteImageToList = QtWidgets.QPushButton("-")
|
||||
controlLayout = QtWidgets.QHBoxLayout()
|
||||
ok = QtWidgets.QPushButton("保存")
|
||||
cancel = QtWidgets.QPushButton("取消")
|
||||
description.setPlaceholderText("可以填写故障的现象、复现步骤以及其他有关的信息,同时也可以填写联系方式")
|
||||
addImageToList.clicked.connect(AddImageToListClicked)
|
||||
deleteImageToList.clicked.connect(DeleteImageToListClicked)
|
||||
ok.clicked.connect(OkClicked)
|
||||
cancel.clicked.connect(CancelClicked)
|
||||
addImageToList.setSizePolicy(size)
|
||||
deleteImageToList.setSizePolicy(size)
|
||||
ok.setSizePolicy(size)
|
||||
cancel.setSizePolicy(size)
|
||||
layout.addWidget(QtWidgets.QLabel("<h2>描述(建议填写)</h2>"), 0, 0)
|
||||
layout.addWidget(description, 1, 0, 1, 3)
|
||||
layout.addWidget(QtWidgets.QLabel("<hr>"), 2, 0, 1, 4)
|
||||
layout.addWidget(QtWidgets.QLabel("<h2>截图(建议选择)</h2>"), 3, 0)
|
||||
layout.addWidget(imageListView, 4, 0, 4, 3)
|
||||
layout.addWidget(addImageToList, 5, 3)
|
||||
layout.addWidget(deleteImageToList, 6, 3)
|
||||
layout.addLayout(controlLayout, 8, 2, 1, 2)
|
||||
controlLayout.addWidget(cancel)
|
||||
controlLayout.addWidget(ok)
|
||||
messagebox.setLayout(layout)
|
||||
messagebox.exec_()
|
||||
|
||||
def To7z(self, savePath):
|
||||
os.system("rm -rfv /tmp/wine-runner-log")
|
||||
os.system("mkdir -v /tmp/wine-runner-log")
|
||||
self.ToHtml("/tmp/wine-runner-log/index.html", toZip=True)
|
||||
shutil.copy(self.binIconPath, f"/tmp/wine-runner-log/{os.path.basename(self.binIconPath)}")
|
||||
if os.path.exists(self.binIconPath):
|
||||
shutil.copy(self.binIconPath, f"/tmp/wine-runner-log/{os.path.basename(self.binIconPath)}")
|
||||
lists = ["wine-runner-log-icon.png", "index.html"]
|
||||
for i in self.imgPath:
|
||||
name = os.path.basename(i)
|
||||
@@ -167,17 +266,35 @@ class SaveLog():
|
||||
imgPath = ""
|
||||
lsmod = ""
|
||||
lshw = ""
|
||||
charReplaceMap = {
|
||||
"<": "<",
|
||||
">": ">",
|
||||
"&": "&",
|
||||
'"': """
|
||||
}
|
||||
for i in self.description.splitlines():
|
||||
for k in charReplaceMap:
|
||||
i = i.replace(k, charReplaceMap[k])
|
||||
description += f'<span class="line code">{i}</span>\n'
|
||||
for i in self.logOut.splitlines():
|
||||
for k in charReplaceMap:
|
||||
i = i.replace(k, charReplaceMap[k])
|
||||
logOut += f'<span class="line code">{i}</span>\n'
|
||||
for i in self.cpuInfo.splitlines():
|
||||
for k in charReplaceMap:
|
||||
i = i.replace(k, charReplaceMap[k])
|
||||
cpuInfo += f'<span class="line code">{i}</span>\n'
|
||||
for i in self.memoryInfo.splitlines():
|
||||
for k in charReplaceMap:
|
||||
i = i.replace(k, charReplaceMap[k])
|
||||
memoryInfo += f'<span class="line code">{i}</span>\n'
|
||||
for i in self.lsmod.splitlines():
|
||||
for k in charReplaceMap:
|
||||
i = i.replace(k, charReplaceMap[k])
|
||||
lsmod += f'<span class="line code">{i}</span>\n'
|
||||
for i in self.lshw.splitlines():
|
||||
for k in charReplaceMap:
|
||||
i = i.replace(k, charReplaceMap[k])
|
||||
lshw += f'<span class="line code">{i}</span>\n'
|
||||
text = readtxt(f"{programPath}/Resources/LogTemplate/template.html")
|
||||
if toZip:
|
||||
@@ -223,14 +340,11 @@ class SaveLog():
|
||||
"%Lsmod%": lsmod,
|
||||
"%Lshw%": lshw,
|
||||
"%CPU%": self.cpu,
|
||||
"%GPU%": self.gpu
|
||||
"%GPU%": self.gpu,
|
||||
"%SystemVersion%": self.systemVersion
|
||||
}
|
||||
for i in replaceMap.keys():
|
||||
text = text.replace(i, replaceMap[i])
|
||||
with open(savePath, "w") as file:
|
||||
file.write(text)
|
||||
|
||||
|
||||
|
||||
|
||||
SaveLog("a", "b", "c", "/opt/apps/deepin-wine-runner/geek.exe", "e", "f", ["/tmp/wine-runner-log/wine-runner-log-icon.png"]).To7z("/tmp/a.7z")
|
||||
Reference in New Issue
Block a user