Merge branch 'feature/recursive-input' into develop

pull/5/head
mandlm 2018-11-10 18:29:31 +01:00
commit 6deefc7ea8
4 changed files with 16 additions and 3 deletions

View File

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

View File

@ -1,3 +1,4 @@
Flask==1.0.2
Pillow==5.3.0
Click==7.0
waitress==1.1.0

8
server.py Executable file
View File

@ -0,0 +1,8 @@
#!/usr/bin/python3
from waitress import serve
import slider
serve(slider.app, host="0.0.0.0", port=8080)

View File

@ -14,6 +14,7 @@ import config
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)
@ -25,7 +26,6 @@ def random():
@app.route("/random_image/")
def random_image():
img_glob = "*jpg"
last_modified_time, last_modified_file = max(
(f.stat().st_mtime, f) for f in imgdir.glob(img_glob)
)
@ -36,7 +36,10 @@ def random_image():
images = list(imgdir.glob(img_glob))
selected_image = choice(images).relative_to(imgdir)
return redirect(url_for("image", filename=selected_image) + "?hash=%s" % get_cache_filename(selected_image))
return redirect(
url_for("image", filename=selected_image)
+ "?hash=%s" % get_cache_filename(selected_image)
)
@app.route("/img/<path:filename>")
@ -77,7 +80,7 @@ def get_cache_filename(filename):
def pre_cache_images():
for image_file in sorted(imgdir.glob("*.jpg")):
for image_file in sorted(imgdir.glob(img_glob)):
create_cache_file(image_file.relative_to(imgdir))