import configparser
import os

from API2 import log_decorator



class ReadSystemIni:
    @log_decorator
    def __init__(self):
        """读取系统的ini文件"""
        self.data_conf_path=os.path.join(os.path.dirname(os.path.dirname(__file__)), "data_config")
        ini_path=os.path.join(self.data_conf_path,"system_config.ini")
        self.conf = configparser.ConfigParser()
        self.conf.read(ini_path, encoding='utf-8')


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

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

    @log_decorator
    def get_username(self,key):
        """根据key，获取用户存放数据的目录名称"""
        return self.conf.get('user',key)

if __name__ == '__main__':
    req = ReadSystemIni()
    print(req.get_username('user1'))