2019-04-09 04:10:08 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# GenThumb.py - Part of the simple s3 gallery
|
|
|
|
# Usage: ./GenThumb.py
|
|
|
|
|
|
|
|
from pathlib import Path
|
|
|
|
from PIL import Image
|
|
|
|
import logging
|
|
|
|
import _thread
|
|
|
|
import time
|
|
|
|
|
|
|
|
logging.basicConfig(filename='GenThumb.log', level=logging.DEBUG,
|
|
|
|
format='%(asctime)s [%(levelname)s] %(message)s',
|
|
|
|
datefmt='%m/%d/%Y %I:%M:%S %p')
|
|
|
|
logging.info("---------------")
|
|
|
|
|
|
|
|
baseuri = "https://s3.wasabisys.com/c0de-photography/"
|
|
|
|
s3_path = "/mnt/photos/"
|
2019-04-09 07:37:57 +00:00
|
|
|
browse_path = "EOS 30D/MFF 2016"
|
2019-04-09 04:10:08 +00:00
|
|
|
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]"))
|
|
|
|
|
2019-04-09 06:42:32 +00:00
|
|
|
def gen_thumb(image, imagepath):
|
2019-04-09 05:38:15 +00:00
|
|
|
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)
|
2019-04-09 04:10:08 +00:00
|
|
|
|
|
|
|
if image.name in "%s" % thumblist:
|
|
|
|
logging.debug("Skipping %s" % image)
|
|
|
|
else:
|
|
|
|
logging.info("Generating thumbnail for New Image: %s" % (image))
|
|
|
|
|
|
|
|
img = Image.open(image)
|
|
|
|
img.thumbnail(thumbsize)
|
|
|
|
img.save(thumbname)
|
|
|
|
|
|
|
|
logging.info("Saved Thumbnail as %s" % thumbname)
|
|
|
|
|
2019-04-09 07:37:57 +00:00
|
|
|
with open('pathlist_%s.txt' % browse_path.replace('/', ':'), 'w') as pathlist:
|
2019-04-09 04:10:08 +00:00
|
|
|
for image in filelist:
|
2019-04-09 06:42:32 +00:00
|
|
|
imagepath = "%s" % image.parent
|
|
|
|
imagepath = imagepath.strip(s3_path)
|
2019-04-09 07:37:57 +00:00
|
|
|
# The pathlist file is used by GenTemplate.py to generate a specific gallery for a specific directory and its children
|
2019-04-09 06:42:32 +00:00
|
|
|
pathlist.write(baseuri + imagepath + '/' + image.name + '\n')
|
2019-04-09 04:10:08 +00:00
|
|
|
try:
|
2019-04-09 05:38:15 +00:00
|
|
|
# WARNING: Each file found will become a thread! Be sure your computer can handle the load
|
2019-04-09 06:42:32 +00:00
|
|
|
_thread.start_new_thread(gen_thumb, (image, imagepath,))
|
2019-04-09 04:10:08 +00:00
|
|
|
time.sleep(0.15)
|
|
|
|
except:
|
|
|
|
logging.error("unable to start thread")
|
|
|
|
|
|
|
|
logging.info("Wait for all threads to save")
|
|
|
|
|
|
|
|
while(1):
|
|
|
|
pass
|
|
|
|
|