-
Notifications
You must be signed in to change notification settings - Fork 0
/
error_report.py
247 lines (158 loc) · 7.4 KB
/
error_report.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
#!/usr/bin/python3
# -*- coding: utf-8 -*
import datetime
import os.path
from allplan_manage import *
from ui_error_report import Ui_ErrorReport
from tools import afficher_message, find_folder_path, open_folder, open_file, read_file_to_text
from send2trash import send2trash
class ErrorReport(QWidget):
def __init__(self, asc):
super().__init__()
# ---------------------------------------
# LOADING UI
# ---------------------------------------
self.ui = Ui_ErrorReport()
self.ui.setupUi(self)
self.setWindowTitle(application_title)
# ---------------------------------------
# LOADING PARENT
# ---------------------------------------
self.asc = asc
self.asc.langue_change.connect(lambda main=self: self.ui.retranslateUi(main))
self.allplan: AllplanDatas = self.asc.allplan
# ---------------------------------------
# SIGNAl
# ---------------------------------------
self.ui.version_list.currentIndexChanged.connect(self.report_version_changed)
self.ui.error_edit.clicked.connect(self.report_edit_clicked)
self.ui.error_open.clicked.connect(self.report_open_clicked)
self.ui.error_delete.clicked.connect(self.report_delete_clicked)
self.ui.error_refresh.clicked.connect(self.report_version_changed)
self.ui.quit.clicked.connect(self.close)
def report_show(self):
self.ui.version_list.blockSignals(True)
version_list = list()
for version_name, version_obj in self.allplan.version_datas.items():
if not isinstance(version_obj, AllplanPaths) or not isinstance(version_name, str):
print("error_report -- report_version_changed -- not isinstance(version_name, str)")
continue
if version_name in version_list:
print("error_report -- report_version_changed -- version_name in version_list")
continue
tmp_path = version_obj.tmp_path
report_path = f"{tmp_path}XML-Validation-Error.log"
if not os.path.exists(report_path):
version_list.append(version_name)
continue
version_list.append(version_name)
if len(version_list) == 0:
afficher_message(titre=self.windowTitle(),
message=self.tr("Aucun rapport d'erreurs trouvées."))
self.ui.version_list.blockSignals(False)
return False
version_list.sort(reverse=True)
self.ui.version_list.clear()
self.ui.version_list.addItems(version_list)
if self.allplan.version_allplan_current in version_list:
index_current = version_list.index(self.allplan.version_allplan_current)
self.ui.version_list.setCurrentIndex(index_current)
self.report_version_changed()
self.ui.version_list.blockSignals(False)
self.show()
return True
@staticmethod
def a___________________tools______():
pass
def report_get_current_path(self) -> str:
version_current = self.ui.version_list.currentText()
if version_current not in self.allplan.version_datas:
print("error_report -- report_get_current_path -- version_current not in self.allplan.version_datas")
return ""
version_obj = self.allplan.version_datas[version_current]
if not isinstance(version_obj, AllplanPaths):
print("error_report -- report_get_current_path -- not isinstance(version_obj, AllplanPaths)")
return ""
tmp_path = version_obj.tmp_path
report_path = f"{tmp_path}XML-Validation-Error.log"
if not os.path.exists(report_path):
return ""
return report_path
def report_manage_buttons(self, active: bool):
self.ui.error_edit.setEnabled(active)
self.ui.error_open.setEnabled(active)
self.ui.error_delete.setEnabled(active)
self.ui.error_refresh.setEnabled(active)
@staticmethod
def a___________________version_changed______():
pass
def report_version_changed(self):
self.ui.report.clear()
report_path = self.report_get_current_path()
if report_path == "":
self.ui.report.setPlainText(self.tr("Aucun rapport d'erreurs trouvées."))
self.ui.error_date.setText(self.tr("Aucun rapport d'erreurs trouvées."))
self.report_manage_buttons(active=False)
return
report_datas = read_file_to_text(file_path=report_path)
if report_datas == "":
print(f"error_report -- report_version_changed --report_datas is empty")
self.ui.report.setPlainText(self.tr("Une erreur est survenue."))
self.ui.error_date.setText(self.tr("Une erreur est survenue."))
self.report_manage_buttons(active=False)
return
self.report_manage_buttons(active=True)
self.ui.report.setPlainText(report_datas)
try:
timestamp_modification = os.path.getmtime(report_path)
date_modification = datetime.datetime.fromtimestamp(timestamp_modification)
date_format = date_modification.strftime('%Y/%m/%d %H:%M')
except Exception as error:
print(f"error_report -- report_get_infos -- error : {error}")
self.ui.error_date.setText(self.tr("Une erreur est survenue."))
return False
if not isinstance(date_format, str):
self.ui.error_date.setText(self.tr("Une erreur est survenue."))
return False
txt_modify = self.tr("Date")
self.ui.error_date.setText(f"{txt_modify} : {date_format}")
return True
@staticmethod
def a___________________buttons______():
pass
def report_edit_clicked(self):
report_path = self.report_get_current_path()
if report_path == "":
return
open_file(file_path=report_path)
def report_open_clicked(self):
report_path = self.report_get_current_path()
if report_path == "":
return
folder_path = find_folder_path(file_path=report_path)
open_folder(folder_path=folder_path)
def report_delete_clicked(self):
report_path = self.report_get_current_path()
if report_path == "":
return
if afficher_message(titre=application_title,
message=self.tr("Voulez-vous supprimer ce rapport?"),
type_bouton=QMessageBox.Ok | QMessageBox.No,
defaut_bouton=QMessageBox.Ok,
icone_question=True) != QMessageBox.Ok:
return
try:
send2trash(report_path)
except Exception as error:
print(f"error_report -- report_delete_clicked -- error : {error}")
self.report_version_changed()
@staticmethod
def a___________________event______():
pass
def keyPressEvent(self, event: QKeyEvent):
if event.key() == Qt.Key_Escape:
self.close()
super().keyPressEvent(event)
@staticmethod
def a___________________end______():
pass