# -*-coding:utf-8 -*- #
# ---------------------------------------------------------------------------
# ProjectName:   PythonProject_1
# FileName:      read_ini.py
# Author:       H_M
# Datetime:     2024/9/3 17:44
# Description:
# ---------------------------------------------------------------------------
import os
import configparser
from MyApiAutoTest_v3 import log


class BasicReadIni:
    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, 'basic_config.ini')
        print(self.data_config_path)
        self.con = configparser.ConfigParser()
        self.con.read(ini_path, encoding="utf-8")

    def get_host(self, key):
        """根据key获取域名路径"""
        try:
            return self.con.get('host', key)
        except Exception as e:
            log.error(f"执行get_host发生错误,错误的key为{key}, 错误为{e}")

    def get_sql(self, key):
        """根据key获取sql节点"""
        try:
            return self.con.get('sql', key)
        except Exception as e:
            log.error(f"执行get_sql发生错误,错误的key为{key}, 错误为{e}")


