[docs]defset_config(path:str)->bool:"""Sets the global configuration for the backend. :param path: The path to the configuration file. :return: True if the configuration file was successfully loaded. """globalAPP_CONFIG# use absolute path for extra explicitnessabs_path:str=abspath(path)LOG.info("Reading configuration from %s",abs_path)try:withopen(abs_path,'r')asconfig_file:APP_CONFIG=safe_load(config_file)returnTrueexcept(FileNotFoundError,YAMLError):LOG.exception("Failed to access config at %s",abs_path)APP_CONFIG=NonereturnFalse
[docs]defget_config()->dict|None:"""Gets the set configuration for the backend. :return: A dictionary containing the configuration for the backend. """returnAPP_CONFIG
[docs]defget_path_to_generated_folder(data_source:str)->str:"""Gets the path to the generated folder for a given data source. If it does not exist, it will be created. :param data_source: The data source for which the path is requested. :return: The path to the generated folder for the given data source. Empty string is returned in case of error. """# load backend configbackend_config:dict=get_config()ifnotbackend_config:# config is emptyLOG.error("Config is empty")return""# Get the path to the data source folderpath_to_data_source:str=join(backend_config['uploads-folder'],data_source)ifnotisdir(path_to_data_source):LOG.error(f"Data source {data_source} not found.")return""# Path to the generated folderpath_to_generated_folder:str=join(path_to_data_source,backend_config['generated-folder-name'])# Check whether it exists, if not create itifnotisdir(path_to_generated_folder):makedirs(path_to_generated_folder)LOG.info(f"Created directory {path_to_generated_folder}.")returnpath_to_generated_folder
[docs]defdata_source_name_from_cube_path(path_to_cube:str)->str:"""Gets the name of the data source from the path to the cube. :param path_to_cube: The path to the cube :return: The name of the data source where the cube is located """returnPath(path_to_cube).parent.name