exception handling -> printing, xmp identification and handling

This commit is contained in:
Xevion
2019-11-01 23:03:31 -05:00
parent 30bb135216
commit f267a43a26
2 changed files with 35 additions and 26 deletions

View File

@@ -21,33 +21,37 @@ from . import RAW_EXTS, LOSSY_EXTS
# 3) Read XMP, then write new tags to it
# 4) Delete temporary file, move NEF/JPEG and XMP
# Driver code for the package
def run():
# Client
client = vision.ImageAnnotatorClient()
# Find files we want to process based on if they have a corresponding .XMP
logging.info('Locating processable files...')
files = os.listdir(INPUT_PATH)
select = [file for file in files if os.path.splitext(file)[1] != '.xmp']
logging.info(f'Found {len(files)} valid files')
# Create the 'temp' directory
logging.info(f'Found {len(files)} valid files, beginning processing...')
logging.info('Creating temporary processing directory')
os.makedirs(TEMP_PATH)
try:
# Process files
for index, file in progressbar.progressbar(list(enumerate(select)), redirect_stdout=True, term_width=110):
_, ext = os.path.splitext(file)
ext = ext[1:]
if ext in LOSSY_EXTS or ext in RAW_EXTS:
logging.info(f"Processing file '{file}'...")
file = FileProcessor(file)
logging.info(f"Processing file '{file}'...")
file.run(client)
except:
logging.warning('Removing temporary directory before raising exception.')
except Exception as error:
logging.error(str(error))
logging.warning(
'Removing temporary directory before raising exception.')
os.rmdir(TEMP_PATH)
raise
# Remove the directory, we are done here
logging.info('Removing temporary directory.')
os.rmdir(TEMP_PATH)
os.rmdir(TEMP_PATH)