Allow author creation by api.
[wolnelektury.git] / src / waiter / utils.py
1 # This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later.
2 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
3 #
4 from os.path import abspath, join, exists
5 from shutil import rmtree
6 from waiter.settings import WAITER_ROOT
7
8
9 def check_abspath(path):
10     abs_path = abspath(join(WAITER_ROOT, path))
11     if not abs_path.startswith(WAITER_ROOT):
12         raise ValueError('Path not inside WAITER_ROOT.')
13     return abs_path
14
15
16 def clear_cache(path):
17     abs_path = check_abspath(path)
18     if exists(abs_path):
19         rmtree(abs_path)