-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRedCheckParser.py
More file actions
142 lines (113 loc) · 5.28 KB
/
Copy pathRedCheckParser.py
File metadata and controls
142 lines (113 loc) · 5.28 KB
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
from __future__ import annotations
import sys
from pathlib import Path
from PyQt5 import QtWidgets
from PyQt5.QtWidgets import QFileDialog, QMessageBox
import design
import parsers
from fstec import find_default_vullist
APP_DIR = Path(__file__).resolve().parent
class RedCheckParserWindow(QtWidgets.QMainWindow, design.Ui_MainWindow):
def __init__(self) -> None:
super().__init__()
self.setupUi(self)
self.radioButton.toggled.connect(self.radio1_clicked)
self.radioButton_2.toggled.connect(self.radio2_clicked)
self.radioButton_3.toggled.connect(self.radio3_clicked)
self.pushButton_3.clicked.connect(self.select_file_updates)
self.pushButton_4.clicked.connect(self.select_file_modernization)
self.pushButton_6.clicked.connect(self.generate_report)
self.pushButton_5.clicked.connect(self.select_file_mapping)
self.pushButton.clicked.connect(self.select_file_before)
self.pushButton_2.clicked.connect(self.select_file_after)
def _select_file(self, title: str, file_filter: str) -> str:
return QFileDialog.getOpenFileName(
self,
title,
str(Path.home()),
file_filter,
)[0]
def select_file_modernization(self) -> None:
self.lineEdit.setText(self._select_file("Выберите XML", "XML Files (*.xml)"))
def select_file_before(self) -> None:
self.lineEdit_4.setText(self._select_file("Выберите XML до работ", "XML Files (*.xml)"))
def select_file_after(self) -> None:
self.lineEdit_5.setText(self._select_file("Выберите XML после работ", "XML Files (*.xml)"))
def select_file_mapping(self) -> None:
self.lineEdit_2.setText(self._select_file("Выберите CSV", "CSV Files (*.csv)"))
def select_file_updates(self) -> None:
self.lineEdit_3.setText(self._select_file("Выберите XML", "XML Files (*.xml)"))
def _default_vullist(self) -> Path | None:
return find_default_vullist([Path.cwd(), APP_DIR])
def generate_report(self) -> None:
self.lineEdit_6.setText("Выполняется…")
QtWidgets.QApplication.processEvents()
try:
vullist_path = self._default_vullist()
address_map = self.lineEdit_2.text() or None
if self.radioButton.isChecked():
if not self.lineEdit.text():
raise ValueError("Не выбран XML-отчёт.")
output = parsers.modernization(
self.lineEdit.text(),
address_map=address_map,
vullist_path=vullist_path,
output_path=Path.cwd() / "report-modernization.xlsx",
)
elif self.radioButton_2.isChecked():
if not self.lineEdit_4.text() or not self.lineEdit_5.text():
raise ValueError("Нужно выбрать отчёты до и после работ.")
output = parsers.service_comparison(
self.lineEdit_4.text(),
self.lineEdit_5.text(),
address_map=address_map,
vullist_path=vullist_path,
output_path=Path.cwd() / "report-service-comparison.xlsx",
)
elif self.radioButton_3.isChecked():
if not self.lineEdit_3.text():
raise ValueError("Не выбран XML-отчёт.")
output = parsers.updates(
self.lineEdit_3.text(),
output_path=Path.cwd() / "report-updates.xlsx",
)
else:
raise ValueError("Выберите тип отчёта.")
self.lineEdit_6.setText(f"Готово: {output.name}")
except Exception as exc:
self.lineEdit_6.setText("Ошибка")
QMessageBox.critical(self, "Ошибка", str(exc))
def radio1_clicked(self, enabled: bool) -> None:
if enabled:
self.lineEdit_6.setText("")
self.pushButton_4.setEnabled(True)
self.pushButton_5.setEnabled(True)
self.pushButton.setEnabled(False)
self.pushButton_2.setEnabled(False)
self.pushButton_6.setEnabled(True)
self.pushButton_3.setEnabled(False)
def radio2_clicked(self, enabled: bool) -> None:
if enabled:
self.lineEdit_6.setText("")
self.pushButton.setEnabled(True)
self.pushButton_2.setEnabled(True)
self.pushButton_4.setEnabled(False)
self.pushButton_5.setEnabled(True)
self.pushButton_6.setEnabled(True)
self.pushButton_3.setEnabled(False)
def radio3_clicked(self, enabled: bool) -> None:
if enabled:
self.lineEdit_6.setText("")
self.pushButton.setEnabled(False)
self.pushButton_2.setEnabled(False)
self.pushButton_4.setEnabled(False)
self.pushButton_5.setEnabled(False)
self.pushButton_3.setEnabled(True)
self.pushButton_6.setEnabled(True)
def main() -> int:
app = QtWidgets.QApplication(sys.argv)
window = RedCheckParserWindow()
window.show()
return app.exec_()
if __name__ == "__main__":
raise SystemExit(main())