create directories

This commit is contained in:
David Todd 2019-04-09 00:38:15 -05:00
parent 4e2517bcff
commit a71a06a765
1 changed files with 5 additions and 3 deletions

View File

@ -19,7 +19,6 @@ browse_path = "EOS M100/"
thumb_path = "./thumbs" thumb_path = "./thumbs"
thumbsize = (250, 250) thumbsize = (250, 250)
logging.info("Getting Paths (Can take time on large directories)") logging.info("Getting Paths (Can take time on large directories)")
filelist = list(Path(s3_path + browse_path).rglob("*.[jJ][pP][gG]")) filelist = list(Path(s3_path + browse_path).rglob("*.[jJ][pP][gG]"))
thumblist = list(Path(thumb_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): def gen_thumb(image):
imagepath = "%s" % image.parent imagepath = "%s" % image.parent
imagepath = imagepath.strip(s3_path) imagepath = imagepath.strip(s3_path)
pathlist.write(baseuri + imagepath + image.name) pathlist.write(baseuri + imagepath + '/' + image.name)
thumbname = "%s/%s:%s" % (thumb_path, 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: if image.name in "%s" % thumblist:
logging.debug("Skipping %s" % image) logging.debug("Skipping %s" % image)
@ -38,12 +38,14 @@ def gen_thumb(image):
img = Image.open(image) img = Image.open(image)
img.thumbnail(thumbsize) img.thumbnail(thumbsize)
img.save(thumbname) 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) logging.info("Saved Thumbnail as %s" % thumbname)
with open('pathlist.txt', 'w') as pathlist: with open('pathlist.txt', 'w') as pathlist:
for image in filelist: for image in filelist:
try: try:
# WARNING: Each file found will become a thread! Be sure your computer can handle the load
_thread.start_new_thread(gen_thumb, (image,)) _thread.start_new_thread(gen_thumb, (image,))
time.sleep(0.15) time.sleep(0.15)
except: except: