# -*-coding:utf-8 -*- #
# ---------------------------------------------------------------------------
# ProjectName:   test66
# FileName:      read_ini.py
# Author:       lao_zhao
# Datetime:     2025/5/9 11:21
# Description:
# 
# ---------------------------------------------------------------------------
import configparser
import os

from APIAutoTest_v3 import log_decorator


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

    @log_decorator
    def get_file_path(self, key):
        """根据key，获取file节点下文件的路径"""
        return os.path.join(self.data_config_path, self.conf.get("file", key))

    @log_decorator
    def get_host(self, key):
        """根据key，获取被测系统的域名"""
        return self.conf.get("url", key)

    @log_decorator
    def get_table_name(self, key):
        """根据key，获取工作表的名称"""
        return self.conf.get("table", key)

    @log_decorator
    def get_sql_connect_msg(self, key):
        """根据key，获取数据库的链接信息"""
        return self.conf.get("sql", key)


if __name__ == '__main__':
    ini = ReadIni()
    print(ini.get_table_name)
    print(ini.get_file_path("case"))
    print(ini.get_host("host"))