From 07fd3bdce5109abbc39ba38aa87428ecd3b5c4d0 Mon Sep 17 00:00:00 2001 From: Michael Mandl Date: Sat, 10 Nov 2018 20:31:34 +0100 Subject: [PATCH] Added cachedir=auto config option --- config.py | 2 +- slider.py | 15 ++++++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/config.py b/config.py index 3098ac2..ab20603 100644 --- a/config.py +++ b/config.py @@ -1,5 +1,5 @@ imgdir = "." recursive = True refresh = 5 -cachedir = "/tmp/webslider" +cachedir = "auto" resolution = (1920, 1080) diff --git a/slider.py b/slider.py index 700ac90..e7b2250 100755 --- a/slider.py +++ b/slider.py @@ -8,6 +8,7 @@ from time import time from hashlib import sha256 import click from shutil import rmtree +from tempfile import gettempdir import config @@ -16,7 +17,11 @@ app = Flask(__name__) imgdir = Path(config.imgdir).expanduser().resolve() img_glob = "**/*.jpg" if config.recursive else "*.jpg" cache_resolution = config.resolution -cache_dir = Path(config.cachedir) / ("%sx%s" % cache_resolution) +cache_dir = ( + Path(gettempdir()) / "webslider" + if config.cachedir == "auto" + else Path(config.cachedir) +) / ("%sx%s" % cache_resolution) @app.route("/") @@ -53,9 +58,9 @@ def image(filename): def rm_cachedir(): - if Path(config.cachedir).exists(): - print("Removing cache dir", config.cachedir) - rmtree(config.cachedir) + if cache_dir.exists(): + print("Removing cache dir", cache_dir) + rmtree(cache_dir) def create_cachedir(): @@ -98,7 +103,7 @@ def run_slider(build_cache, clear_cache): if build_cache: pre_cache_images() - app.run() + app.run(host="0.0.0.0") if __name__ == "__main__":