ref: pass cmdline params into fn explicitly

rrr-marble 5 years ago
parent 0970ca42ee
commit b6adc6a5c6

@ -13,26 +13,21 @@ DB_LOCATION = (
"db/photovoter.dblite" # Q: any allowances for this being not OUR database? "db/photovoter.dblite" # Q: any allowances for this being not OUR database?
) )
# place compressed images here (needs to exist) # place compressed images here (needs to exist)
DEST_STRUNK = "db/image/" DEST_SHRUNK = "db/image/"
# move originals here (needs to exist) # move originals here (needs to exist)
DEST_ORIGINAL = "db/original/" DEST_ORIGINAL = "db/original/"
def usage(): def process_pictures(source: str, dest_shrunk: str, dest_original: str):
"""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):
"""Process images from the base directory in the first command line argument. """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. move the originals to dest_original.
Return a dict for each image processed for database collection. Return a dict for each image processed for database collection.
""" """
# walk every pic # walk every pic
# We only care about files in the root of the path # We only care about files in the root of the path
# Ignore any nested directories # 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: for filename in filenames:
# FIXME[0]:what if picture with the same name already exists? # FIXME[0]:what if picture with the same name already exists?
# skip any non-image files # 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.strip() # Q: may damage icc, do we allow that or use smh else?
cloned.transform(resize="50%") # Q: what do we want here? cloned.transform(resize="50%") # Q: what do we want here?
# move them to the processed folder # 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 # move the originals out of the working directory
# Q: do we strip exif from originals? # 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 # return the freshly processed picture info
yield { yield {
"ResizedImage": path.join(dest_strunk, filename), "ResizedImage": path.join(dest_shrunk, filename),
"OriginalImage": path.join(dest_original, filename), "OriginalImage": path.join(dest_original, filename),
"DateTimeOriginal": exif["DateTimeOriginal"], # Q: normalize it? "DateTimeOriginal": exif["DateTimeOriginal"], # Q: normalize it?
"GPSLatitude": exif["GPSLatitude"], "GPSLatitude": exif["GPSLatitude"],
@ -167,23 +162,33 @@ def check_database(database_path: str):
con.close() con.close()
def main(): def run(db_location: str, source: str, dest_shrunk: str, dest_original: str):
if len(argv) != 2: """Core program logic"""
usage()
exit(1)
pics_processed = 0 pics_processed = 0
# process each pic and add it to the database # process each pic and add it to the database
for pic in process_pictures(DEST_STRUNK, DEST_ORIGINAL): for pic in process_pictures(source, dest_shrunk, dest_original):
update_database(pic, DB_LOCATION) update_database(pic, db_location)
pics_processed += 1 pics_processed += 1
if pics_processed == 0: 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?") print("Do we have enough permissions?")
else: else:
print("Pictures processed:", pics_processed) 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__": if __name__ == "__main__":
main() main()

Loading…
Cancel
Save