summaryrefslogtreecommitdiff
path: root/check/app/utils/file_utils.py
diff options
context:
space:
mode:
authoradamhrv <adam@ahprojects.com>2019-04-23 12:57:20 +0200
committeradamhrv <adam@ahprojects.com>2019-04-23 12:57:20 +0200
commit23e8e2222e4577d346e21003ab2f83ef36bfdb55 (patch)
tree0f8e78a28a071aab15f9641e17214a6b74c9dcc3 /check/app/utils/file_utils.py
parent7660929b0fea77d0548596e4f116ff4217f7661b (diff)
mod utils
Diffstat (limited to 'check/app/utils/file_utils.py')
-rw-r--r--check/app/utils/file_utils.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/check/app/utils/file_utils.py b/check/app/utils/file_utils.py
index 5c7b39d..1ed1833 100644
--- a/check/app/utils/file_utils.py
+++ b/check/app/utils/file_utils.py
@@ -310,6 +310,25 @@ def mkdirs(fp):
fpp = fpp.parent if fpp.suffix else fpp
fpp.mkdir(parents=True, exist_ok=True)
+def ensure_posixpath(fp):
+ """Ensures filepath is pathlib.Path
+ :param fp: a (str, LazyFile, PosixPath)
+ :returns: a PosixPath filepath object
+ """
+ if type(fp) == str:
+ fpp = Path(fp)
+ elif type(fp) == click.utils.LazyFile:
+ fpp = Path(fp.name)
+ elif type(fp) == pathlib.PosixPath:
+ fpp = fp
+ else:
+ raise TypeError('{} is not a valid filepath type'.format(type(fp)))
+ return fpp
+
+def ensure_dir(fp):
+ if not Path(fp).is_dir():
+ mkdirs(fp)
+
def ext_media_format(ext):
"""Converts file extension into Enum MediaType