h2integrate.resource.utilities.file_tools

h2integrate.resource.utilities.file_tools#

Functions

check_resource_dir([resource_dir, ...])

Checks for a folder to contain resource files, or creates one if necessary.

h2integrate.resource.utilities.file_tools.check_resource_dir(resource_dir=None, resource_subdir=None)#

Checks for a folder to contain resource files, or creates one if necessary. If resource_dir is input, the logic is as follows:

  1. Check that resource_dir exists, if it doesn't, then create a folder.

    Note: If resource_dir is a relative filepath, it is assumed relative to the current working directory.

  2. If resource_subdir is None, then return the full path resource_dir.

    Otherwise, calls this function again with

    >>> check_resource_dir(resource_dir=str(resource_dir / resource_subdir))
    

If resource_dir is not input, the logic is as follows:

  1. Check for an environment variable named RESOURCE_DIR.

    If this environment variable exists, follow the logic in Steps 1-2.

  2. Use RESOURCE_DEFAULT_DIR as the resource_dir and follow the logic in Steps 1-2.

Parameters:
  • resource_dir (Path | str, optional) -- Path of directory that has resource files. Defaults to None.

  • resource_subdir (str, optional) -- folder name within resource_dir. Defaults to None.

Returns:

Path -- valid directory to save resource files to or load resource files from.