|
|
|
|
@ -18,21 +18,16 @@ DEST_SHRUNK = "db/image/"
|
|
|
|
|
DEST_ORIGINAL = "db/original/"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def usage():
|
|
|
|
|
"""Brief usage explanation"""
|
|
|
|
|
print("USAGE: python {name} /path/to/images".format(name=argv[0]), file=stderr)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def process_pictures(dest_strunk: str, dest_original: str):
|
|
|
|
|
def process_pictures(source: str, dest_shrunk: str, dest_original: str):
|
|
|
|
|
"""Process images from the base directory in the first command line argument.
|
|
|
|
|
Place the resized copies to DEST_STRUNK and
|
|
|
|
|
Place the resized copies to dest_shrunk and
|
|
|
|
|
move the originals to dest_original.
|
|
|
|
|
Return a dict for each image processed for database collection.
|
|
|
|
|
"""
|
|
|
|
|
# walk every pic
|
|
|
|
|
# We only care about files in the root of the path
|
|
|
|
|
# Ignore any nested directories
|
|
|
|
|
(root, _, filenames) = next(walk(argv[1], topdown=True), (None, None, []))
|
|
|
|
|
(root, _, filenames) = next(walk(source, topdown=True), (None, None, []))
|
|
|
|
|
for filename in filenames:
|
|
|
|
|
# FIXME[0]:what if picture with the same name already exists?
|
|
|
|
|
# skip any non-image files
|
|
|
|
|
@ -49,7 +44,7 @@ def process_pictures(dest_strunk: str, dest_original: str):
|
|
|
|
|
cloned.strip() # Q: may damage icc, do we allow that or use smh else?
|
|
|
|
|
cloned.transform(resize="50%") # Q: what do we want here?
|
|
|
|
|
# move them to the processed folder
|
|
|
|
|
cloned.save(filename=path.join(dest_strunk, filename))
|
|
|
|
|
cloned.save(filename=path.join(dest_shrunk, filename))
|
|
|
|
|
|
|
|
|
|
# move the originals out of the working directory
|
|
|
|
|
# Q: do we strip exif from originals?
|
|
|
|
|
@ -57,7 +52,7 @@ def process_pictures(dest_strunk: str, dest_original: str):
|
|
|
|
|
|
|
|
|
|
# return the freshly processed picture info
|
|
|
|
|
yield {
|
|
|
|
|
"ResizedImage": path.join(dest_strunk, filename),
|
|
|
|
|
"ResizedImage": path.join(dest_shrunk, filename),
|
|
|
|
|
"OriginalImage": path.join(dest_original, filename),
|
|
|
|
|
"DateTimeOriginal": exif["DateTimeOriginal"], # Q: normalize it?
|
|
|
|
|
"GPSLatitude": exif["GPSLatitude"],
|
|
|
|
|
@ -167,23 +162,33 @@ def check_database(database_path: str):
|
|
|
|
|
con.close()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
|
if len(argv) != 2:
|
|
|
|
|
usage()
|
|
|
|
|
exit(1)
|
|
|
|
|
|
|
|
|
|
def run(db_location: str, source: str, dest_shrunk: str, dest_original: str):
|
|
|
|
|
"""Core program logic"""
|
|
|
|
|
pics_processed = 0
|
|
|
|
|
# process each pic and add it to the database
|
|
|
|
|
for pic in process_pictures(DEST_STRUNK, DEST_ORIGINAL):
|
|
|
|
|
update_database(pic, DB_LOCATION)
|
|
|
|
|
for pic in process_pictures(source, dest_shrunk, dest_original):
|
|
|
|
|
update_database(pic, db_location)
|
|
|
|
|
pics_processed += 1
|
|
|
|
|
|
|
|
|
|
if pics_processed == 0:
|
|
|
|
|
print("No more pictures processed from", argv[1])
|
|
|
|
|
print("No more pictures processed from", source)
|
|
|
|
|
print("Do we have enough permissions?")
|
|
|
|
|
else:
|
|
|
|
|
print("Pictures processed:", pics_processed)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def usage():
|
|
|
|
|
"""Brief usage explanation"""
|
|
|
|
|
print("USAGE: python {name} /path/to/images".format(name=argv[0]), file=stderr)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
|
if len(argv) != 2:
|
|
|
|
|
usage()
|
|
|
|
|
exit(1)
|
|
|
|
|
|
|
|
|
|
run(DB_LOCATION, argv[1], DEST_SHRUNK, DEST_ORIGINAL)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
main()
|
|
|
|
|
|