# -*-coding:utf-8 -*- #
# ---------------------------------------------------------------------------
# ProjectName:   test_58
# FileName:      read_ini.py
# Author:       xxxxxxx
# Datetime:     2024/1/4 9:40
# Description:
# 
# ---------------------------------------------------------------------------
import configparser
import os
from InterfaceAutoTest.data_config.settings import *


class ReadIni:
    def __init__(self):
        """获取ini文件的路径，并创建Configparser对象，再读取ini文件"""
        # 获取data_config的路径
        self.data_config_path = os.path.join(os.path.dirname(os.path.dirname(__file__)), "data_config")
        # 获取ini文件的路径
        ini_path = os.path.join(self.data_config_path, "config.ini")
        # 创建Configparser对象
        self.conf = configparser.ConfigParser()
        # 读取ini文件
        self.conf.read(ini_path, encoding="utf-8")

    def get_host(self, key):
        """根据key， 获取被测系统的域名"""
        try:
            # Configparser对象调用get方法获取节点下key对应的值
            host = self.conf.get(HOST, key)
            return host
        except:
            raise KeyError("传入的key错误~~")
        # else:
        #     return host

    def get_sql_connect_msg(self, key):
        """根据key 获取数据库的链接信息"""
        try:
            # Configparser对象调用get方法获取节点下key对应的值
            msg = self.conf.get(SQL, key)
        except:
            raise KeyError("传入的key错误~~")
        else:
            return msg


