# -*-coding:utf-8 -*- #
# ---------------------------------------------------------------------------
# ProjectName:   test65
# FileName:      read_ini.py
# Author:       lao_zhao
# Datetime:     2025/3/12 11:16
# Description:
# 
# ---------------------------------------------------------------------------
import configparser
import os

from APIAutoTest_v3 import log_decorator


class ReadSystemIni:

    @log_decorator
    def __init__(self):
        """获取ini文件的路径，使用Configparser对象读取ini文件"""
        self.data_config = os.path.join(os.path.dirname(os.path.dirname(__file__)), "data_config")
        ini_path = os.path.join(self.data_config, "system_config.ini")
        self.conf = configparser.ConfigParser()
        self.conf.read(ini_path, encoding="utf-8")

    @log_decorator
    def get_server_value(self, key):
        """根据key，获取server节点下服务器的信息"""
        return self.conf.get("server", key)

    @log_decorator
    def get_sql_connect_mgs(self, key):
        """根据key，获取mysql节点下数据库的连接的信息"""
        return self.conf.get("MySql", key)

    @log_decorator
    def get_user_name(self, key):
        """根据key，获取用户的名称"""
        return self.conf.get("user", key)


if __name__ == '__main__':
    ini = ReadSystemIni()
    ini.get_sql_connect_mgs("host")
    ini.get_server_value("host")