# -*-coding:utf-8 -*- #
# ---------------------------------------------------------------------------
# ProjectName:   test
# FileName:      read_user_ini.py
# Author:       mwx
# Datetime:     2024/11/5 18:34
# Description:
# 
# ---------------------------------------------------------------------------
import configparser
import os

from Interface_automation.APIAutoText_v3_1_1 import log


class ReadUserIni:
    def __init__(self,user):
        file_path = os.path.join(os.path.dirname(os.path.dirname(__file__)),"data_cofig")
        self.user_path = os.path.join(file_path,user)
        self.ini_oath = os.path.join(self.user_path,"config.ini")
        self.conf = configparser.ConfigParser()
        self.conf.read(self.ini_oath,encoding="utf-8")


    def file_name(self,key):
        log.info(f"读取{key}下的ini文件中的数据")
        try:
            file_path = self.conf.get("file",key)
            return os.path.join(self.user_path,file_path)
        except Exception as e:
            log.error(f"获取file节点下的数据错误，错误类型为{e},检查传入的{key}")
            raise e

    def table_name(self,key):
        try:
            return self.conf.get("table",key)
        except Exception as e:
            log.error(f"获取table节点下的数据错误，错误类型为{e},检查传入的{key}")
            raise e



if __name__ == '__main__':
    d = ReadUserIni("mw")
    print(d.file_name("excel"))










