mirror of
https://github.com/Xevion/phototag.git
synced 2025-12-06 03:15:51 -06:00
removal of large amounts of archaic file processing and printing in favor of simplicity
This commit is contained in:
13
package/__main__.py
Normal file
13
package/__main__.py
Normal file
@@ -0,0 +1,13 @@
|
||||
import os
|
||||
import logging
|
||||
|
||||
from . import INPUT_PATH, OUTPUT_PATH
|
||||
|
||||
# Ensure that 'input' and 'output' directories are created
|
||||
if not os.path.exists(INPUT_PATH):
|
||||
logging.fatal('Input directory did not exist, creating and quitting.')
|
||||
os.makedirs(INPUT_PATH)
|
||||
|
||||
if not os.path.exists(OUTPUT_PATH):
|
||||
logging.info('Output directory did not exist. Creating...')
|
||||
os.makedirs(OUTPUT_PATH)
|
||||
@@ -27,25 +27,20 @@ def run():
|
||||
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']
|
||||
|
||||
# Create the 'temp' directory
|
||||
print(f'Initializing file processing for {len(select)} files...')
|
||||
logging.info(f'Found {len(files)} valid files, beginning processing...')
|
||||
os.makedirs(TEMP_PATH)
|
||||
|
||||
try:
|
||||
# Process files
|
||||
for index, file in progressbar.progressbar(list(enumerate(select)), redirect_stdout=True, term_width=110):
|
||||
name, ext = os.path.splitext(file)
|
||||
ext = ext.lower().strip('.')
|
||||
# Raw files contain their metadata in an XMP file usually
|
||||
if ext in RAW_EXTS:
|
||||
print('Processing file {}, \'{}\''.format(index + 1, xmps[0]), end=' | ')
|
||||
file = FileProcessor(file, xmps[0])
|
||||
file.run(client)
|
||||
elif ext in LOSSY_EXTS:
|
||||
print('Processing file {}, \'{}\''.format(index + 1, file), end=' | ')
|
||||
_, ext = os.path.splitext(file)
|
||||
if ext in LOSSY_EXTS or ext in RAW_EXTS:
|
||||
logging.info(f"Processing file '{file}'...")
|
||||
file = FileProcessor(file)
|
||||
file.run(client)
|
||||
except:
|
||||
|
||||
Reference in New Issue
Block a user