# -*-coding:utf-8 -*- #
# ---------------------------------------------------------------------------
# ProjectName:   test61
# FileName:      read_basic_ini.py
# Author:       lao_zhao
# Datetime:     2024/7/12 16:48
# Description:
# 
# ---------------------------------------------------------------------------
import os, configparser


class ReadBasicIni:
    def __init__(self):
        """获取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, "basic_config.ini")
        self.conf = configparser.ConfigParser()
        self.conf.read(ini_path, encoding="utf-8")

    def get_url(self, key):
        """根据key，获取被测系统的域名"""
        try:
            return self.conf.get("host", key)
        except Exception as e:
            raise e

    def sql_connect_msg(self, key):
        """根据key，获取数据库的链接信息"""
        try:
            return self.conf.get("sql", key)
        except Exception as e:
            raise e

    def get_log_dir(self, key):
        """根据key获取日志存放的目录"""
        try:
            # 获取日志存放的目录名称
            dir_name = self.conf.get("report", key)
        except Exception as e:
            raise e
        else:
            # 获取report目录路径
            report_path = os.path.join(os.path.dirname(os.path.dirname(__file__)), "report")
            # 拼接日志文件的目录路径，再返回
            return os.path.join(report_path, dir_name)