# -*-coding:utf-8 -*- #
# ---------------------------------------------------------------------------
# ProjectName:   test59
# FileName:      read_ini.py
# Author:       laozhao
# Datetime:     2024/3/18 15:20
# Description:
# 
# ---------------------------------------------------------------------------
import configparser
import os

from InterfaceAutoTest import log_decorator


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

    @log_decorator
    def get_file_path(self, key, username):
        """根据key获取file节点下文件的路径"""
        try:
            value = self.conf.get("file", key)
        except:
            raise KeyError("输入的key错误")
        else:
            return os.path.join(os.path.join(self.data_config, username), value)

    @log_decorator
    def get_table_name(self, key):
        """根据key获取table节点下key对应的工作表名称"""
        try:
            value = self.conf.get("table", key)
        except:
            raise KeyError("输入的key错误")
        else:
            return value

    @log_decorator
    def get_host(self, key):
        """根据key获取host节点下key对应的域名"""
        try:
            value = self.conf.get("host", key)
        except:
            raise KeyError("输入的key错误")
        else:
            return value

    @log_decorator
    def get_sql_connect_msg(self, key):
        """根据key获取sql节点下key对应的数据库链接信息"""
        try:
            value = self.conf.get("sql", key)
        except:
            raise KeyError("输入的key错误")
        else:
            return value

if __name__ == '__main__':
    ini = ReadIni()
    print(ini.get_file_path("excel", "张三"))