geotribu_cli.utils.check_path module

Helpers to check file: readable, exists, etc..

Author: Julien Moura (https://github.com/guts)

geotribu_cli.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.

Paramètres:
  • 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.

Lève:
  • 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

Renvoie:

True if the path complies with constraints.

Type renvoyé:

bool

geotribu_cli.utils.check_path.check_path_exists(input_path, raise_error=True)

Check if the input path (file or folder) exists.

Paramètres:
  • input_path (Union[str, Path]) – path to check

  • raise_error (bool, optional) – if True, it raises an exception. Defaults to True.

Lève:

FileExistsError – if the path doesn’t exist and raise_error is False

Renvoie:

True if the path exists.

Type renvoyé:

bool

geotribu_cli.utils.check_path.check_path_is_readable(input_path, raise_error=True)

Check if the input path (file or folder) is readable.

Paramètres:
  • input_path (Path) – path to check

  • raise_error (bool, optional) – if True, it raises an exception. Defaults to True.

Lève:

FileExistsError – if the path is not readable and raise_error is False

Renvoie:

True if the path is readable.

Type renvoyé:

bool

geotribu_cli.utils.check_path.check_path_is_writable(input_path, raise_error=True)

Check if the input path (file or folder) is writable.

Paramètres:
  • input_path (Path) – path to check

  • raise_error (bool, optional) – if True, it raises an exception. Defaults to True.

Lève:

FileExistsError – if the path is not writable and raise_error is False

Renvoie:

True if the path is writable.

Type renvoyé:

bool

geotribu_cli.utils.check_path.check_var_can_be_path(input_var, raise_error=True)

Check is the path can be converted as pathlib.Path.

Paramètres:
  • input_var (str) – var to check

  • raise_error (bool, optional) – if True, it raises an exception. Defaults to True.

Lève:

TypeError – if input path can’t be converted and raise_error is False

Renvoie:

True if the input can be converted to pathlib.Path

Type renvoyé:

bool