dicogis.utils.check_path module¶
Helpers to check file: readable, exists, etc..
Author: Julien Moura (https://github.com/guts)
- dicogis.utils.check_path.check_folder_is_empty(input_var, raise_error=True)¶
Check if a variable is valid path, exists, is a folder and is empty.
- dicogis.utils.check_path.check_path(input_path, must_exists=True, must_be_readable=True, must_be_writable=False, must_be_a_folder=False, must_be_a_file=False, raise_error=True)¶
Meta function of the module. Check if a given path complies with some constraints.
- Parameters:
input_path (Union[str, Path]) – path to check
must_exists (bool, optional) – path must exist. Defaults to True.
must_be_readable (bool, optional) – path must be readable. Defaults to True.
must_be_writable (bool, optional) – path must be writable. Defaults to False.
must_be_a_folder (bool, optional) – path must be a folder. Mutually exclusive with must_be_a_file. Defaults to False.
must_be_a_file (bool, optional) – path must be a file. Mutually exclusive with must_be_a_folder. Defaults to False.
raise_error (bool, optional) – if True, it raises an exception. Defaults to True.
- Raises:
ValueError – if must_be_a_file and must_be_a_folder are both set to True
FileNotFoundError – if the path is not a file and must_be_a_file is set to True
NotADirectoryError – if the path is not a folder and must_be_a_folder is set to True
- Returns:
True if the path complies with constraints.
- Return type:
- dicogis.utils.check_path.check_path_exists(input_path, attempt=1, raise_error=True)¶
Check if the input path (file or folder) exists.
- Parameters:
- Raises:
FileExistsError – if the path doesn’t exist and raise_error is False
- Returns:
True if the path exists.
- Return type:
- dicogis.utils.check_path.check_path_is_readable(input_path, raise_error=True)¶
Check if the input path (file or folder) is readable.
- Parameters:
input_path (Path) – path to check
raise_error (bool, optional) – if True, it raises an exception. Defaults to True.
- Raises:
FileExistsError – if the path is not readable and raise_error is False
- Returns:
True if the path is readable.
- Return type:
- dicogis.utils.check_path.check_path_is_writable(input_path, raise_error=True)¶
Check if the input path (file or folder) is writable.
- Parameters:
input_path (Path) – path to check
raise_error (bool, optional) – if True, it raises an exception. Defaults to True.
- Raises:
FileExistsError – if the path is not writable and raise_error is False
- Returns:
True if the path is writable.
- Return type:
- dicogis.utils.check_path.check_var_can_be_path(input_var, attempt=1, raise_error=True)¶
Check is the path can be converted as pathlib.Path.
- Parameters:
- Raises:
TypeError – if input path can’t be converted and raise_error is False
ValueError – if input path is an empty string
- Returns:
True if the input can be converted to pathlib.Path
- Return type: