handle error processing file

This commit is contained in:
Antonio J. Delgado 2023-12-23 10:28:10 +02:00
parent 5092a2f6d0
commit 98945baa3b
3 changed files with 11 additions and 7 deletions

View file

@ -88,7 +88,10 @@ class image_classifier:
entries.append(entry) entries.append(entry)
self._log.info(f"Processing {len(entries)} files...") self._log.info(f"Processing {len(entries)} files...")
for entry in entries: for entry in entries:
try:
self.process_file(entry.path) self.process_file(entry.path)
except Exception as error:
self._log.error(f"Error processing file '{entry.path}'. {error}")
def count(self, iterable): def count(self, iterable):
''' Return the length of an iterable that can't be count with len()''' ''' 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}" f"Error copying. File not found. {error}"
) )
if not self.no_move: 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( self._log.debug(
f"Destination '{new_path}/{filename}' exists, \ f"Destination '{full_path}' exists, \
removing it..." removing it..."
) )
os.remove(os.path.join(new_path, filename)) os.remove(full_path)
self._log.info(f"Moving file '{file}' to '{new_path}'...") self._log.info(f"Moving file '{file}' to '{new_path}'...")
try: try:
shutil.move(file, new_path) shutil.move(file, new_path)

View file

@ -1,8 +1,8 @@
[metadata] [metadata]
name = image_classifier name = image_classifier
version = 0.0.19 version = 0.0.20
[options] [options]
packages = image_classifier packages = image_classifier
install_requires = install_requires =
importlib; python_version == "3.6" importlib; python_version == "3.10"

View file

@ -9,7 +9,7 @@ if os.access(requirements_file, os.R_OK):
setuptools.setup( setuptools.setup(
scripts=['image_classifier/image_classifier.py'], scripts=['image_classifier/image_classifier.py'],
author="Antonio J. Delgado", author="Antonio J. Delgado",
version='0.0.19', version='0.0.20',
name='image_classifier', name='image_classifier',
author_email="antoniodelgado@susurrando.com", author_email="antoniodelgado@susurrando.com",
url="", url="",