Code layout change.
[wolnelektury.git] / src / waiter / utils.py
diff --git a/src/waiter/utils.py b/src/waiter/utils.py
new file mode 100644 (file)
index 0000000..68d21bd
--- /dev/null
@@ -0,0 +1,20 @@
+# -*- coding: utf-8 -*-
+# This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later.
+# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
+#
+from os.path import abspath, join, exists
+from shutil import rmtree
+from waiter.settings import WAITER_ROOT
+
+
+def check_abspath(path):
+    abs_path = abspath(join(WAITER_ROOT, path))
+    if not abs_path.startswith(WAITER_ROOT):
+        raise ValueError('Path not inside WAITER_ROOT.')
+    return abs_path
+
+
+def clear_cache(path):
+    abs_path = check_abspath(path)
+    if exists(abs_path):
+        rmtree(abs_path)