hlcc 2.0.0-beta2+pre1
Loading...
Searching...
No Matches
Functions
utils.file_helper Namespace Reference

Functions

def find_file (filepath, root_directories=["CFGPATH"], resource_directories=[], exception=False, log_level=logging.INFO)
 Verifies that the given input file path exist in one of the root directories.
 
def resolve_path (path)
 Resolve the given path.
 
def configure_logger (str logger_name, log_level=logging.INFO)
 Configure logging with predefined formatting and set loglevel.
 

Function Documentation

◆ configure_logger()

def utils.file_helper.configure_logger ( str  logger_name,
  log_level = logging.INFO 
)

Configure logging with predefined formatting and set loglevel.

Parameters
logger_namelogger name
levellog level
Returns
logger

◆ find_file()

def utils.file_helper.find_file (   filepath,
  root_directories = ["CFGPATH"],
  resource_directories = [],
  exception = False,
  log_level = logging.INFO 
)

Verifies that the given input file path exist in one of the root directories.

Parameters
filepathThe file to search (as a relative path)
type of filepath: str
root_directoriesA list of environment variables defining search paths (: separated) to search (default: ["CFGPATH"])
type of root_directories: list or str
resource_directoriesA list of resource directories to search for inside the
root_directories[]). The following are examples of common resource directories that may be used ["config", "audio", "image", "model", "dictionary", "data"].
type of resource_directories: list of str
exceptionIf True it throws an exception if file not not found. If False (default) it returns an empty string if file not found
type of exception: bool
Returns
Fully qualified file path if file was found or empty string if NOT found.
return type of : str
Exceptions
Exceptionif file was not found (and param exception = True).

Root search paths are loaded from the environment variables in root_directories and the elements of the search path are iterated.

For each path, the file is currently searched iterating for each res_dir in the resource_directories but also for resource/res_dir

The search stops at the first full match and the result is returned.

If the search fails, an empty string is returned or an exception is thrown depending on the value of the exception parameter.

◆ resolve_path()

def utils.file_helper.resolve_path (   path)

Resolve the given path.