From bc0ee53d88953e28a262c7826de7dbefb200aba2 Mon Sep 17 00:00:00 2001 From: Michael Mandl Date: Sat, 10 Nov 2018 16:23:04 +0100 Subject: [PATCH] Expand ~ in source dir path --- config.py | 3 ++- requirements.txt | 1 + slider.py | 9 ++++----- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/config.py b/config.py index 5e666a9..ce3bda5 100644 --- a/config.py +++ b/config.py @@ -1,3 +1,4 @@ imgdir = "." refresh = 5 -cachedir = ".webslider" +cachedir = "/tmp/webslider" +resolution = (1920, 1080) diff --git a/requirements.txt b/requirements.txt index f1a6954..533b660 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,3 @@ Flask==1.0.2 Pillow==5.3.0 +Click==7.0 diff --git a/slider.py b/slider.py index da7d743..52b56a1 100755 --- a/slider.py +++ b/slider.py @@ -13,7 +13,8 @@ import config app = Flask(__name__) -cache_resolution = (1920, 1080) +imgdir = Path(config.imgdir).expanduser().resolve() +cache_resolution = config.resolution cache_dir = Path(config.cachedir) / ("%sx%s" % cache_resolution) @@ -25,7 +26,6 @@ def random(): @app.route("/random_image/") def random_image(): img_glob = "*jpg" - imgdir = Path(config.imgdir) last_modified_time, last_modified_file = max( (f.stat().st_mtime, f) for f in imgdir.glob(img_glob) ) @@ -64,7 +64,7 @@ def create_cache_file(filename): if not (cache_dir / cache_file).exists(): print("Creating cache file", filename) - img = Image.open(Path(config.imgdir) / filename) + img = Image.open(imgdir / filename) img.thumbnail(cache_resolution) img.save(cache_dir / cache_file, "JPEG") @@ -72,12 +72,11 @@ def create_cache_file(filename): def get_cache_filename(filename): - original_file_path = Path(config.imgdir) / filename + original_file_path = imgdir / filename return sha256(str(original_file_path.resolve()).encode("utf-8")).hexdigest() def pre_cache_images(): - imgdir = Path(config.imgdir) for image_file in sorted(imgdir.glob("*.jpg")): create_cache_file(image_file.relative_to(imgdir))