1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- from .WorkWithDB import connect, list_propusk
- from sqlalchemy import select
- 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
-
- if os.path.exists(path):
- self._files_in_db = self._get_list_files_from_db()
- else:
- logger.error(F"Не корректный путь: {path}")
- sys.exit(0)
- def _get_list_files_from_db(self) -> list:
- 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()
-
- 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)
-
- def clear(self) -> None:
- _, _, files = os.walk(self._path).__next__()
- for file in files:
- if file not in self._files_in_db:
- os.remove(os.path.join(self._path, file))
- logger.info(F"Удален файл: {os.path.join(self._path, file)}")
|