From 98945baa3b7be1f39f515e35d4f6055a31fe72c3 Mon Sep 17 00:00:00 2001 From: "Antonio J. Delgado" Date: Sat, 23 Dec 2023 10:28:10 +0200 Subject: [PATCH] handle error processing file --- image_classifier/image_classifier.py | 12 ++++++++---- setup.cfg | 4 ++-- setup.py | 2 +- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/image_classifier/image_classifier.py b/image_classifier/image_classifier.py index 46ce862..851450f 100755 --- a/image_classifier/image_classifier.py +++ b/image_classifier/image_classifier.py @@ -88,7 +88,10 @@ class image_classifier: entries.append(entry) self._log.info(f"Processing {len(entries)} files...") for entry in entries: - self.process_file(entry.path) + try: + self.process_file(entry.path) + except Exception as error: + self._log.error(f"Error processing file '{entry.path}'. {error}") def count(self, iterable): ''' Return the length of an iterable that can't be count with len()''' @@ -236,12 +239,13 @@ folder, '{person_path}'...") f"Error copying. File not found. {error}" ) if not self.no_move: - if os.path.exists(os.path.join(new_path, filename)): + full_path = os.path.join(new_path, filename) + if os.path.exists(full_path): self._log.debug( - f"Destination '{new_path}/{filename}' exists, \ + f"Destination '{full_path}' exists, \ removing it..." ) - os.remove(os.path.join(new_path, filename)) + os.remove(full_path) self._log.info(f"Moving file '{file}' to '{new_path}'...") try: shutil.move(file, new_path) diff --git a/setup.cfg b/setup.cfg index 337c5ab..a4a2573 100755 --- a/setup.cfg +++ b/setup.cfg @@ -1,8 +1,8 @@ [metadata] name = image_classifier -version = 0.0.19 +version = 0.0.20 [options] packages = image_classifier install_requires = - importlib; python_version == "3.6" + importlib; python_version == "3.10" diff --git a/setup.py b/setup.py index b91f3bf..12cfdc5 100755 --- a/setup.py +++ b/setup.py @@ -9,7 +9,7 @@ if os.access(requirements_file, os.R_OK): setuptools.setup( scripts=['image_classifier/image_classifier.py'], author="Antonio J. Delgado", - version='0.0.19', + version='0.0.20', name='image_classifier', author_email="antoniodelgado@susurrando.com", url="",