logging additions and removal of archaic .XMP sidecar file "detection"

This commit is contained in:
Xevion
2019-11-01 22:22:38 -05:00
parent ade2f7c018
commit 96685e33d3
4 changed files with 19 additions and 44 deletions

View File

@@ -1,9 +1,11 @@
import sys
import os
import logging
from package import app
os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = os.path.join(
sys.path[0], 'package', 'key', 'photo_tagging_service.json')
if __name__ == "__main__":
logging.info('Executing package...')
sys.exit(app.run())

View File

@@ -1,5 +1,8 @@
import os
import sys
import logging
logging.basicConfig(level=logging.INFO)
# Path Constants
ROOT = sys.path[0]
@@ -7,6 +10,7 @@ PROCESSING_PATH = os.path.join(ROOT, 'package', 'processing')
INPUT_PATH = os.path.join(PROCESSING_PATH, 'input')
TEMP_PATH = os.path.join(PROCESSING_PATH, 'temp')
OUTPUT_PATH = os.path.join(PROCESSING_PATH, 'output')
logging.info('Path Constants Built.')
# Extension Constants
RAW_EXTS = [

View File

@@ -1,8 +1,16 @@
import io, sys, os, time, rawpy, imageio, progressbar, shutil
import io
import sys
import os
import time
import rawpy
import imageio
import progressbar
import shutil
import logging
from .xmp import XMPParser
from google.cloud import vision
from .xmp import XMPParser
from .process import FileProcessor
from . import INPUT_PATH, TEMP_PATH, OUTPUT_PATH, PROCESSING_PATH
from . import RAW_EXTS, LOSSY_EXTS
@@ -15,16 +23,6 @@ from . import RAW_EXTS, LOSSY_EXTS
# Driver code for the package
def run():
# Ensure that 'input' and 'output' directories are created
if not os.path.exists(INPUT_PATH):
print('Input directory did not exist, creating and quitting.')
os.makedirs(INPUT_PATH)
return
if not os.path.exists(OUTPUT_PATH):
print('Output directory did not exist. Creating...')
os.makedirs(OUTPUT_PATH)
# Client
client = vision.ImageAnnotatorClient()
@@ -43,33 +41,9 @@ def run():
ext = ext.lower().strip('.')
# Raw files contain their metadata in an XMP file usually
if ext in RAW_EXTS:
# Get all possible files
identicals = [possible for possible in files
if possible.startswith(os.path.splitext(file)[0])
and not possible.endswith(os.path.splitext(file)[1])
and not possible.upper().endswith('.XMP')]
# Alert the user that there are duplicates in the directory and ask whether or not to continue
if len(identicals) > 0:
print('Identical files were the directory, continue?')
print(',\n\t'.join(identicals))
xmps = [possible for possible in files
if possible.startswith(os.path.splitext(file)[0])
and possible.upper().endswith('.XMP')]
# Skip and warn if more than 1 possible files, user error
if len(xmps) > 1:
print('More than 1 possible XMP metadata file for \'{}\'...'.format(file))
print(',\n'.join(['\t{}'.format(possible) for possible in xmps]))
# Zero possible files, user error, likely
elif len(xmps) <= 0:
print('No matching XMP metadata file for \'{}\'. skipping...'.format(file))
# Process individual file
else:
print('Processing file {}, \'{}\''.format(index + 1, xmps[0]), end=' | ')
file = FileProcessor(file, xmps[0])
file.run(client)
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=' | ')
file = FileProcessor(file)

View File

@@ -32,19 +32,14 @@ class FileProcessor(object):
rgb.close()
# Information on file sizes
print("Raw Size: {} {}".format(*self._size(os.path.join(INPUT_PATH, self.file_name))), end=' | ')
print("Resave Size: {} {}".format(*self._size(self.temp_file_path)), end=' | ')
pre = os.path.getsize(self.temp_file_path)
self._optimize(self.temp_file_path)
post = os.path.getsize(self.temp_file_path)
print("Optimized Size: {} {} ({}% savings)".format(*self._size(self.temp_file_path), round((1.0 - (post / pre)) * 100), 2) )
def basicOptimize(self):
pre = os.path.getsize(os.path.join(INPUT_PATH, self.file_name))
self._optimize(os.path.join(INPUT_PATH, self.file_name), copy=self.temp_file_path)
post = os.path.getsize(self.temp_file_path)
print("Optimized Size: {} {} ({}% savings)".format(*self._size(self.temp_file_path), round((1.0 - (post / pre)) * 100), 2) )
def run(self, client):
try: