|
@@ -1,9 +1,12 @@
|
|
|
from .WorkWithDB import connect, list_propusk
|
|
|
from sqlalchemy import select
|
|
|
-from appdirs import user_data_dir
|
|
|
-import os
|
|
|
+from sqlalchemy.exc import OperationalError
|
|
|
+from MyMessageBox import show_dialog
|
|
|
+from PySide6.QtWidgets import QMessageBox
|
|
|
+import os, sys
|
|
|
from logger import logger
|
|
|
|
|
|
+
|
|
|
class CleanerImage:
|
|
|
def __init__(self, path: str):
|
|
|
self._path = path
|
|
@@ -12,23 +15,31 @@ class CleanerImage:
|
|
|
self._files_in_db = self._get_list_files_from_db()
|
|
|
else:
|
|
|
logger.error(F"Не корректный путь: {path}")
|
|
|
- raise ValueError(F"Не корректный путь: {path}")
|
|
|
+ sys.exit(0)
|
|
|
|
|
|
def _get_list_files_from_db(self) -> list:
|
|
|
- with connect() as conn:
|
|
|
- list_files = select(
|
|
|
- list_propusk.c.face,
|
|
|
- list_propusk.c.document
|
|
|
- ).select_from(list_propusk)
|
|
|
+ try:
|
|
|
+ with connect() as conn:
|
|
|
+ list_files = select(
|
|
|
+ list_propusk.c.face,
|
|
|
+ list_propusk.c.document
|
|
|
+ ).select_from(list_propusk)
|
|
|
+
|
|
|
+ result = conn.execute(list_files).all()
|
|
|
|
|
|
- result = conn.execute(list_files).all()
|
|
|
+ images = []
|
|
|
+ for face, document in result:
|
|
|
+ images.append(face)
|
|
|
+ images.append(document)
|
|
|
|
|
|
- images = []
|
|
|
- for face, document in result:
|
|
|
- images.append(face)
|
|
|
- images.append(document)
|
|
|
+ return images
|
|
|
+ except OperationalError as er:
|
|
|
+ logger.fatal(er)
|
|
|
+ show_dialog(QMessageBox.Icon.Critical,
|
|
|
+ 'Не обновлена БД',
|
|
|
+ 'Не сходятся таблицы, для исправления перенесите БД в другую директорию или удалите')
|
|
|
+ sys.exit(0)
|
|
|
|
|
|
- return images
|
|
|
|
|
|
def clear(self) -> None:
|
|
|
_, _, files = os.walk(self._path).__next__()
|