mirror of
https://github.com/lucaspalomodevelop/eventcally.git
synced 2026-03-13 00:07:22 +00:00
Clear image cache #148
This commit is contained in:
parent
54a9635b96
commit
5364ac16ea
@ -10,7 +10,6 @@ EXPOSE 5000
|
||||
ENV PYTHONUNBUFFERED=1
|
||||
|
||||
# Environment variables
|
||||
ENV CACHE_PATH=""
|
||||
ENV DATABASE_URL=""
|
||||
ENV GOOGLE_MAPS_API_KEY=""
|
||||
ENV MAIL_DEFAULT_SENDER=""
|
||||
@ -18,7 +17,6 @@ ENV MAIL_PASSWORD=""
|
||||
ENV MAIL_PORT=""
|
||||
ENV MAIL_SERVER=""
|
||||
ENV MAIL_USERNAME=""
|
||||
ENV PROJECT_ENABLE_CRAWLING=""
|
||||
ENV SECRET_KEY=""
|
||||
ENV SECURITY_PASSWORD_HASH=""
|
||||
ENV SERVER_NAME=""
|
||||
|
||||
@ -140,6 +140,7 @@ config_oauth(app)
|
||||
import project.api
|
||||
|
||||
# Command line
|
||||
import project.cli.cache
|
||||
import project.cli.dump
|
||||
import project.cli.event
|
||||
import project.cli.seo
|
||||
|
||||
17
project/cli/cache.py
Normal file
17
project/cli/cache.py
Normal file
@ -0,0 +1,17 @@
|
||||
import click
|
||||
from flask.cli import AppGroup
|
||||
|
||||
from project import app, img_path
|
||||
from project.utils import clear_files_in_dir
|
||||
|
||||
cache_cli = AppGroup("cache")
|
||||
|
||||
|
||||
@cache_cli.command("clear-images")
|
||||
def clear_images():
|
||||
click.echo("Clearing images..")
|
||||
clear_files_in_dir(img_path)
|
||||
click.echo("Done.")
|
||||
|
||||
|
||||
app.cli.add_command(cache_cli)
|
||||
@ -29,6 +29,13 @@ def make_dir(path):
|
||||
os.umask(original_umask)
|
||||
|
||||
|
||||
def clear_files_in_dir(path):
|
||||
with os.scandir(path) as entries:
|
||||
for entry in entries:
|
||||
if entry.is_file() or entry.is_symlink():
|
||||
os.remove(entry.path)
|
||||
|
||||
|
||||
def split_by_crlf(s):
|
||||
return [v for v in s.splitlines() if v]
|
||||
|
||||
|
||||
@ -23,10 +23,6 @@ def image(id):
|
||||
if "s" in request.args:
|
||||
width = int(request.args["s"])
|
||||
height = width
|
||||
elif "w" in request.args:
|
||||
width = int(request.args["w"])
|
||||
elif "h" in request.args:
|
||||
height = int(request.args["h"])
|
||||
|
||||
# Generate file name
|
||||
extension = image.encoding_format.split("/")[-1] if image.encoding_format else "png"
|
||||
|
||||
10
tests/cli/test_cache.py
Normal file
10
tests/cli/test_cache.py
Normal file
@ -0,0 +1,10 @@
|
||||
def test_clear_images(client, seeder, app, utils):
|
||||
user_id, admin_unit_id = seeder.setup_base()
|
||||
image_id = seeder.upsert_default_image()
|
||||
|
||||
url = utils.get_url("image", id=image_id)
|
||||
utils.get_ok(url)
|
||||
|
||||
runner = app.test_cli_runner()
|
||||
result = runner.invoke(args=["cache", "clear-images"])
|
||||
assert "Done." in result.output
|
||||
@ -6,14 +6,12 @@ from project import img_path
|
||||
|
||||
|
||||
@pytest.mark.parametrize("size", [None, 100])
|
||||
@pytest.mark.parametrize("width", [None, 100])
|
||||
@pytest.mark.parametrize("height", [None, 100])
|
||||
def test_read(app, seeder, utils, size, width, height):
|
||||
def test_read(app, seeder, utils, size):
|
||||
user_id, admin_unit_id = seeder.setup_base()
|
||||
image_id = seeder.upsert_default_image()
|
||||
|
||||
shutil.rmtree(img_path, ignore_errors=True)
|
||||
|
||||
url = utils.get_url("image", id=image_id, s=size, w=width, h=height)
|
||||
url = utils.get_url("image", id=image_id, s=size)
|
||||
utils.get_ok(url)
|
||||
utils.get_ok(url) # cache
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user