Added cachedir=auto config option

This commit is contained in:
mandlm 2018-11-10 20:31:34 +01:00
parent d6c46f4060
commit 07fd3bdce5
2 changed files with 11 additions and 6 deletions

View File

@ -1,5 +1,5 @@
imgdir = "." imgdir = "."
recursive = True recursive = True
refresh = 5 refresh = 5
cachedir = "/tmp/webslider" cachedir = "auto"
resolution = (1920, 1080) resolution = (1920, 1080)

View File

@ -8,6 +8,7 @@ from time import time
from hashlib import sha256 from hashlib import sha256
import click import click
from shutil import rmtree from shutil import rmtree
from tempfile import gettempdir
import config import config
@ -16,7 +17,11 @@ app = Flask(__name__)
imgdir = Path(config.imgdir).expanduser().resolve() imgdir = Path(config.imgdir).expanduser().resolve()
img_glob = "**/*.jpg" if config.recursive else "*.jpg" img_glob = "**/*.jpg" if config.recursive else "*.jpg"
cache_resolution = config.resolution 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("/") @app.route("/")
@ -53,9 +58,9 @@ def image(filename):
def rm_cachedir(): def rm_cachedir():
if Path(config.cachedir).exists(): if cache_dir.exists():
print("Removing cache dir", config.cachedir) print("Removing cache dir", cache_dir)
rmtree(config.cachedir) rmtree(cache_dir)
def create_cachedir(): def create_cachedir():
@ -98,7 +103,7 @@ def run_slider(build_cache, clear_cache):
if build_cache: if build_cache:
pre_cache_images() pre_cache_images()
app.run() app.run(host="0.0.0.0")
if __name__ == "__main__": if __name__ == "__main__":