# -*-coding:utf-8 -*- #
# ---------------------------------------------------------------------------
# ProjectName:   test64
# FileName:      read_ini.py
# Author:       lao_zhao
# Datetime:     2024/12/26 10:59
# Description:
# 
# ---------------------------------------------------------------------------
import configparser
import os
from APIAutoTest_v3 import log_decorator



class ReadBasicIni:
    @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_host(self, key):
        """根据key，获取host节点下系统的域名"""
        return self.conf.get("host", key)

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

    @log_decorator
    def get_user_data_dir_name(self, key):
        """根据key，获取用户存放数据的目录路径"""
        # 获取用户存放数据的目录名称
        user_data_dir_name = self.conf.get("user", key)
        # 用户存放数据的目录名称和data_config的目录路径进行路径拼接，再返回
        return os.path.join(self.data_config_path, user_data_dir_name)



if __name__ == '__main__':
    ini = ReadBasicIni()

    print(ini.get_host("bpm"))
    print(ini.get_user_data_dir_name("ww"))
    print(ini.get_database_conn_msg("host"))