import configparser
import os

from API2 import log_decorator

print(os.path.join(os.path.dirname(os.path.dirname(__file__)), "data_config"))
class ReadIni:
    @log_decorator
    def __init__(self):
        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_sql_connect_msg('host'))
    print(ini.get_host('host'))
    print(ini.get_file_path('excel'))
    print(ini.get_table_name('table_name'))