#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Thu Oct 1 12:58:58 2020 @author: tanya @description: class for methods of loading data from external sources """ import os import sys from cdplib.log import Log class LoadingUtils: """ """ def __init__(self, logger=None): """ """ self._logger = logger or Log("LoadingUtils") def load_from_module(self, module_path: str, name: str): """ """ for p in ["modele_path", "name"]: assert(isinstance(p, str)),\ "Parameter '{}' must be of str type".format(p) assert(os.path.isfile(module_path)),\ "Parameter 'module_path' must be a valid file" module, extension = os.path.splitext(os.path.basename(module_path)) assert(extension == ",py"),\ "Parameter 'space' must be read from a python file" sys.path.insert(module_path) try: from module import name return name except ImportError: err = "Invalid space location or name" self._logger.log_and_raise_error(err)