diff options
| author | Jules Laplace <julescarbon@gmail.com> | 2019-04-23 13:10:52 +0200 |
|---|---|---|
| committer | Jules Laplace <julescarbon@gmail.com> | 2019-04-23 13:10:52 +0200 |
| commit | 1b30746ee4d38cd6acdbf339b4605700f07fc02a (patch) | |
| tree | 74c2bbbde7d04bdabf76dd64bfcf652fbb713c05 /check/app/utils/file_utils.py | |
| parent | f5f30912a2efd9c3d47cc9aeaf6a542211b00474 (diff) | |
| parent | 0cb9209d52604e5bf7366b74447ca79576335091 (diff) | |
Merge branch 'master' of github.com:adamhrv/vframe_check_api
Diffstat (limited to 'check/app/utils/file_utils.py')
| -rw-r--r-- | check/app/utils/file_utils.py | 19 |
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 |
