27 lines
836 B
Python
27 lines
836 B
Python
import importlib
|
|
from actions.config.config import Config
|
|
|
|
|
|
class DynamicImport:
|
|
|
|
def __init__(self):
|
|
self.base = 'packages.v1'
|
|
|
|
def set_package(self, name):
|
|
self.package = name
|
|
|
|
def set_table(self, table):
|
|
self.table = table
|
|
|
|
def service(self, name: str, class_name : str):
|
|
try:
|
|
# Define o nome do Módulo
|
|
module_file = f"{name}"
|
|
# Define o caminho do arquivo
|
|
path = f"{self.base}.{self.package}.services.{self.table}.{module_file}"
|
|
# Realiza a importação do arquivo
|
|
module = importlib.import_module(path)
|
|
clazz = getattr(module, class_name)
|
|
return clazz
|
|
except (ImportError, AttributeError) as e:
|
|
raise ImportError(f"Erro ao importar '{class_name}' de '{path}': {e}")
|