# -*-coding:utf-8 -*- #
# ---------------------------------------------------------------------------
# ProjectName:   test63
# FileName:      read_ini.py
# Author:       lao_zhao
# Datetime:     2024/11/5 14:09
# Description:
# 
# ---------------------------------------------------------------------------
import configparser
import os

from APIAutoTest_v3_1 import log


class ReadBasicIni:
    def __init__(self):
        """读取ini文件"""
        self.data_config = os.path.join(os.path.dirname(os.path.dirname(__file__)), "data_config")
        ini_path = os.path.join(self.data_config, "basic_config.ini")
        self.conf = configparser.ConfigParser()
        self.conf.read(ini_path, encoding="utf-8")

    def get_host(self, key):
        """根据key获取host节点下被测系统的域名"""
        log.info(f"执行get_host方法，功能为：根据key获取host节点下被测系统的域名， 传入的参数为：{key}")
        try:
            return self.conf.get("host", key)
        except Exception as e:
            log.info(f"执行get_host方法，功能为：根据key获取host节点下被测系统的域名， 传入的参数为：{key}"
                     f"发生错误，错误的类型为：{type(e)}， 错误的描述为：{e}")
            raise e

    def get_connect_sql_msg(self, key):
        """根据key获取sql节点下数据库的链接信息"""
        log.info(f"执行get_connect_sql_msg方法，功能为：根据key获取sql节点下数据库的链接信息， 传入的参数为：{key}")
        try:
            return self.conf.get("sql", key)
        except Exception as e:
            log.info(f"执行get_connect_sql_msg方法，功能为：根据key获取sql节点下数据库的链接信息， 传入的参数为：{key}"
                     f"发生错误，错误的类型为：{type(e)}， 错误的描述为：{e}")
            raise e


if __name__ == '__main__':
    ini = ReadBasicIni()