# -*-coding:utf-8 -*- #
# ---------------------------------------------------------------------------
# ProjectName:   test62
# FileName:      read_ini.py
# Author:       lao_zhao
# Datetime:     2024/9/4 14:17
# Description:
# 
# ---------------------------------------------------------------------------
import configparser
import os
from apiAutoTest_v3 import log


class ReadIni:
    def __init__(self):
        """获取ini文件的路径，并读取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节点下key对应被测系统的域名"""
        try:
            return self.conf.get("host", key)
        except Exception as e:
            log.error(f"方法get_host执行失败，形参key传参为：{key},错误为：{e}")
            raise e

    def get_sql_connect_msg(self, key):
        """根据key获取sql节点下key对应的数据库链接信息"""
        try:
            return self.conf.get("sql", key)
        except Exception as e:
            log.error(f"方法get_sql_connect_msg执行失败，形参key传参为：{key},错误为：{e}")
            raise e


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