summer_course_2024/hub/helpers/utils.py

24 lines
883 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-05-31 13:53:22 -04:00
functions = [function[1:] for function in dir(cls_name) if (type(getattr(cls_name, function)) is property or callable(getattr(cls_name, function))) and function in cls_name.__dict__ and function[0] == '_' and function != '__init__']
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)