From a71a06a765c7443d607b3ebec7a4771665b3d2d3 Mon Sep 17 00:00:00 2001 From: David Todd Date: Tue, 9 Apr 2019 00:38:15 -0500 Subject: [PATCH] create directories --- GenThumb.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/GenThumb.py b/GenThumb.py index 49da9df..d6f0b7f 100755 --- a/GenThumb.py +++ b/GenThumb.py @@ -19,7 +19,6 @@ browse_path = "EOS M100/" thumb_path = "./thumbs" thumbsize = (250, 250) - logging.info("Getting Paths (Can take time on large directories)") filelist = list(Path(s3_path + browse_path).rglob("*.[jJ][pP][gG]")) thumblist = list(Path(thumb_path).rglob("*.[jJ][pP][gG]")) @@ -27,8 +26,9 @@ thumblist = list(Path(thumb_path).rglob("*.[jJ][pP][gG]")) def gen_thumb(image): imagepath = "%s" % image.parent imagepath = imagepath.strip(s3_path) - pathlist.write(baseuri + imagepath + image.name) - thumbname = "%s/%s:%s" % (thumb_path, imagepath, image.name) + pathlist.write(baseuri + imagepath + '/' + image.name) + Path(thumb_path + '/' + imagepath).mkdir(mode=0o755, parents=True, exist_ok=True) # Generate the path if it doesn't already exist + thumbname = "%s/%s/%s" % (thumb_path, imagepath, image.name) if image.name in "%s" % thumblist: logging.debug("Skipping %s" % image) @@ -38,12 +38,14 @@ def gen_thumb(image): img = Image.open(image) img.thumbnail(thumbsize) img.save(thumbname) + img.close(image) # So we're not wasting memory when the threads wait to get closed logging.info("Saved Thumbnail as %s" % thumbname) with open('pathlist.txt', 'w') as pathlist: for image in filelist: try: + # WARNING: Each file found will become a thread! Be sure your computer can handle the load _thread.start_new_thread(gen_thumb, (image,)) time.sleep(0.15) except: