energy_system_modelling_wor.../hub/helpers/utils.py

28 lines
916 B
Python
Raw Normal View History

"""
Constant module
SPDX - License - Identifier: LGPL - 3.0 - or -later
Copyright © 2023 Concordia CERC group
Project Coder Peter Yefi peteryefi@gmail.com
"""
import logging
def validate_import_export_type(cls_name: type, handler: str):
"""
Retrieves all the function names in a class which are property types (decoration)
and normal functions
:param cls_name: the class name
:param handler: import export handler
:return: None
"""
2023-08-08 12:39:37 -04:00
functions = [
function[1:] for function in dir(cls_name)
if (
isinstance(getattr(cls_name, function), property) or callable(getattr(cls_name, function))
) and function in cls_name.__dict__ and function[0] == '_' and function != '__init__']
2023-05-31 13:53:22 -04:00
if handler.lower() not in functions:
2023-05-31 13:51:35 -04:00
error_message = f'Wrong import type [{handler}]. Valid functions include {functions}'
logging.error(error_message)
raise ValueError(error_message)