Updated _cleanup_tmp_files to fix error during testing
This commit is contained in:
@@ -4,6 +4,7 @@ Processes a Photos.app library database to extract information about photos
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
import os
|
||||||
import os.path
|
import os.path
|
||||||
import pathlib
|
import pathlib
|
||||||
import platform
|
import platform
|
||||||
@@ -155,21 +156,27 @@ class PhotosDB:
|
|||||||
self._process_database5()
|
self._process_database5()
|
||||||
|
|
||||||
def _cleanup_tmp_files(self):
|
def _cleanup_tmp_files(self):
|
||||||
""" removes all temporary files whose names are stored in self.tmp_files """
|
""" removes all temporary files whose names are stored in self.tmp_files
|
||||||
""" does not raise exception if file cannot be deleted (e.g. it was already cleaned up) """
|
does not raise exception if file cannot be deleted (e.g. it was already cleaned up) """
|
||||||
logging.debug(f"tmp files ={self._tmp_files}")
|
|
||||||
|
# logging.debug(f"tmp files = {self._tmp_files}")
|
||||||
for f in self._tmp_files:
|
for f in self._tmp_files:
|
||||||
|
if os.path.exists(f):
|
||||||
logging.debug(f"cleaning up {f}")
|
logging.debug(f"cleaning up {f}")
|
||||||
try:
|
try:
|
||||||
os.remove(f)
|
os.remove(f)
|
||||||
|
self._tmp_files.remove(f)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.debug(f"exception {e} removing {f}")
|
logging.debug("exception %e removing %s" % (e, f))
|
||||||
pass
|
else:
|
||||||
# print(f"WARNING: Unable to remove tmp file {e}")
|
self._tmp_files.remove(f)
|
||||||
# raise e
|
|
||||||
|
|
||||||
def __del__(self):
|
def __del__(self):
|
||||||
self._cleanup_tmp_files()
|
pass
|
||||||
|
# TODO: not sure this is needed as cleanup called in process_database
|
||||||
|
# but commenting out for now as it was causing weird error during testing
|
||||||
|
# AttributeError: 'NoneType' object has no attribute 'exists'
|
||||||
|
# self._cleanup_tmp_files()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def keywords_as_dict(self):
|
def keywords_as_dict(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user