# -*-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 UserReadIni:
    def __init__(self, username):
        self.data_config_path = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'data_config')
        self.user_dir = os.path.join(self.data_config_path, username)
        ini_path = os.path.join(self.user_dir, 'config.ini')
        print(self.data_config_path)
        self.con = configparser.ConfigParser()
        self.con.read(ini_path, encoding="utf-8")

    def get_file_path(self, key):
        """根据key获取文件路径"""
        try:
            file_path = self.con.get('file', key)
        except Exception as e:
            log.error(f"执行get_file_path发生错误，错误的key为{key}, 错误为{e}")
        else:
            return os.path.join(self.user_dir, file_path)

    def get_table(self, key):
        """根据key获取工作表名"""
        try:
            return self.con.get('table', key)
        except Exception as e:
            log.error(f"执行get_table发生错误,错误的key为{key}, 错误为{e}")



