Ver código fonte

add exceptions.py

JustDreamer7 2 anos atrás
pai
commit
61f9eb8c05
3 arquivos alterados com 42 adições e 23 exclusões
  1. 21 22
      UI_report_prisma.py
  2. 19 0
      exceptions.py
  3. 2 1
      make_report_prisma.py

+ 21 - 22
UI_report_prisma.py

@@ -2,11 +2,11 @@ import datetime
 import os
 
 from PyQt6 import QtCore, QtWidgets
-
 from interfaces.clientui import Ui_MainWindow
 from interfaces.drctryChoice import Ui_drctryChoice
 from interfaces.takeFiles import Ui_takeFiles
 from make_report_prisma import make_report_prisma
+from exceptions import DateError
 
 class UIReportPrisma32(QtWidgets.QMainWindow, Ui_MainWindow):
     def __init__(self):
@@ -60,36 +60,35 @@ class UIReportPrisma32(QtWidgets.QMainWindow, Ui_MainWindow):
             ui_report_drctry.lineEdit.setText("")
         self.widget.show()
 
+
     def report_on_click(self):
         """Метод, описывающий получение паспорта с помощью данных UI"""
         start_date = self.dateEdit.date().toPyDate()
         end_date = self.dateEdit_2.date().toPyDate()
-        print(f'start_date - {start_date}, \n end_date - {end_date}')
-        with open('path_prisma_report.txt', 'r') as f:
-            report_path = f.read()
-        picture_path = report_path + '/Pics' + f'/{start_date.year}'
-        with open('path_prisma_1cl_files.txt', 'r') as f:
-            path_to_files_1 = f.read()
-        with open('path_prisma_2cl_files.txt', 'r') as f:
-            path_to_files_2 = f.read()
-        if ~os.path.exists(picture_path):
-            try:
-                os.mkdir(picture_path)
-            except OSError:
-                print(f"Создать директорию {picture_path} не удалось")
-            else:
-                print(f"Успешно создана директория {picture_path}")
-
         try:
+            if start_date > end_date:
+                raise DateError(start_date, end_date)
+            with open('path_prisma_report.txt', 'r') as f:
+                report_path = f.read()
+            picture_path = report_path + '/Pics' + f'/{start_date.year}'
+            with open('path_prisma_1cl_files.txt', 'r') as f:
+                path_to_files_1 = f.read()
+            with open('path_prisma_2cl_files.txt', 'r') as f:
+                path_to_files_2 = f.read()
+            if ~os.path.exists(picture_path):
+                try:
+                    os.mkdir(picture_path)
+                except OSError:
+                    print(f"Создать директорию {picture_path} не удалось")
+                else:
+                    print(f"Успешно создана директория {picture_path}")
             make_report_prisma(start_date=start_date, end_date=end_date, report_path=report_path, picture_path=picture_path,
                                path_to_files_1=path_to_files_1, path_to_files_2 = path_to_files_2)
         except PermissionError:
             print("Закройте предыдущую версию файла!")
-        # проверяем нормальные даты или нет, если да, то графики и word файл строятся
-        # try:
-        #     pass
-        # except ZeroDivisionError:
-        #     pass
+        except DateError:
+            DateError(start_date, end_date).ui_output_error()
+
 
 
 # запуск основного окна

+ 19 - 0
exceptions.py

@@ -0,0 +1,19 @@
+from PyQt6.QtWidgets import QMessageBox
+
+
+class DateError(Exception):
+    def __init__(self, start_date, end_date, message = 'The start date of data processing is greater than the end date'):
+        self.start_date = start_date
+        self.end_date = end_date
+        self.message = message
+        super().__init__(self.message)
+
+    def __str__(self):
+        return f'{self.start_date} > {self.end_date} -> {self.message}'
+
+    def ui_output_error(self):
+        msg = QMessageBox()
+        msg.setText("Date-time Error")
+        msg.setInformativeText(self.__str__())
+        msg.setWindowTitle("Error")
+        msg.exec()

+ 2 - 1
make_report_prisma.py

@@ -41,7 +41,8 @@ def make_report_prisma(start_date, end_date, path_to_files_1, path_to_files_2, r
 
     real_worktime = worktime_frame_2['Worktime'].sum() - 24 * days_amount + worktime_frame_1[
         'Worktime'].sum() + brake_both_cl_time / 60
-    print(brake_both_cl_time)
+
+    print(f'{brake_both_cl_time=}')
 
     graphs.change_design()