aboutsummaryrefslogtreecommitdiff
path: root/gn3/fs_helpers.py
diff options
context:
space:
mode:
Diffstat (limited to 'gn3/fs_helpers.py')
-rw-r--r--gn3/fs_helpers.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/gn3/fs_helpers.py b/gn3/fs_helpers.py
index 845c48b..1b226bc 100644
--- a/gn3/fs_helpers.py
+++ b/gn3/fs_helpers.py
@@ -13,6 +13,20 @@ from typing import List
from typing import ValuesView
from werkzeug.utils import secure_filename
+from flask import current_app
+
+def get_tmpdir() -> str:
+ """Get the temp directory from the FLASK tmpdir setting. If it is not set, set it to /tmp. Note
+ that the app should check for environment settings to initialize its TMPDIR.
+ """
+ tmpdir = current_app.config.get("TMPDIR")
+ if not tmpdir:
+ tmpdir = "/tmp"
+ if not os.path.isdir(tmpdir):
+ raise FileNotFoundError(errno.ENOENT, os.strerror(errno.ENOENT), f"TMPDIR {tmpdir} is not a valid directory")
+
+ return tmpdir
+
def assert_path_exists(path: str, throw_error: bool = True) -> bool:
"""Throw error if any of them do not exist."""
if not os.path.isfile(path):