# -*-coding:utf-8 -*- #
# ---------------------------------------------------------------------------
# ProjectName:   test60
# FileName:      read_ini.py
# Author:       lao_zhao
# Datetime:     2024/5/20 14:02
# Description:
# 
# ---------------------------------------------------------------------------
import configparser
import os

from InterfaceAutoTest import log_decorator
from InterfaceAutoTest.data_config.settings import *


class ReadIni:
    @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_file_path(self, key, username="demo"):
        """根据key获取file节点下文件的路径"""
        try:
            value = self.conf.get(FILE, key)
        except Exception as e:
            raise e
        else:
            username_dir = os.path.join(self.data_config_path, username)
            return os.path.join(username_dir, value)

    @log_decorator
    def get_table_name(self, key):
        """根据key获取工作表名称"""
        try:
            value = self.conf.get(WORKSHEET, key)
        except Exception as e:
            raise e
        else:
            return value

    @log_decorator
    def get_host(self, key):
        """根据key获取域名"""
        try:
            value = self.conf.get(HOST, key)
        except Exception as e:
            raise e
        else:
            return value

    @log_decorator
    def get_db_connect_message(self, key):
        """根据key获取数据库的链接信息"""
        try:
            value = self.conf.get(DB, key)
        except Exception as e:
            raise e
        else:
            return value


if __name__ == '__main__':
    ini = ReadIni()
    print(ini.get_host("bpm"))