# -*-coding:utf-8 -*- #
# ---------------------------------------------------------------------------
# ProjectName:   test64
# FileName:      read_user_ini.py
# Author:       lao_zhao
# Datetime:     2024/12/26 15:45
# Description:
# 
# ---------------------------------------------------------------------------
import configparser
import os
from APIAutoTest_v3 import log_decorator
from APIAutoTest_v3.common.read_basic_ini import ReadBasicIni


class ReadUserIni:
    @log_decorator
    def __init__(self, username):
        """获取项目下用户ini配置文件的路径，创建Configparser对象，读取ini文件"""
        # 创建ReadBasicIni的对象，调用get_user_data_dir_name方法，获取用户存放数据的目录路径
        self.user_data_dir_path = ReadBasicIni().get_user_data_dir_name(username)
        ini_path = os.path.join(self.user_data_dir_path, "config.ini")
        self.conf = configparser.ConfigParser()
        self.conf.read(ini_path, encoding="utf-8")

    @log_decorator
    def get_file_path(self, key):
        """根据key，获取file节点下文件的路径"""
        # try:
        #     file_name = self.conf.get("file", key)
        # except Exception as e:
        #     logging.error(f"key为{key}")   # 添加额外的日志
        #     raise e
        # else:
        #     return
        return os.path.join(self.user_data_dir_path, self.conf.get("file", key))


    @log_decorator
    def get_table_name(self, key):
        """根据key，获取table节点下excel工作表名称"""
        return self.conf.get("table", key)
if __name__=="__main__":
    user=ReadUserIni("ww")
    print(user.user_data_dir_path)
    print(user.get_table_name("name"))