# -*-coding:utf-8 -*- #
# ---------------------------------------------------------------------------
# ProjectName:   test67
# FileName:      read_ini.py
# Author:       lao_zhao
# Datetime:     2025/6/13 14:25
# Description:
# 
# ---------------------------------------------------------------------------
import configparser
import os.path

from APIAutoTest_v3 import log_decorator
from APIAutoTest_v3.utils.read_system_ini import ReadSystemIni


class ReadUserIni:
    @log_decorator
    def __init__(self, username):
        """获取ini文件路径，使用Configparser对象的read方法进行读取"""
        data_config_path = os.path.join(os.path.dirname(os.path.dirname(__file__)), "data_config")
        self.user_data_path = os.path.join(data_config_path, username)
        ini_path = os.path.join(self.user_data_path, "user_config.ini")
        self.conf = configparser.ConfigParser()
        self.conf.read(ini_path, encoding="utf-8")

    @log_decorator
    def get_file_path(self, key):
        """根据key获取文件的路径"""
        return os.path.join(self.user_data_path, self.conf.get("file", key))

    @log_decorator
    def get_table_name(self, key):
        """根据key获取工作表的名称"""
        return self.conf.get("table", key)



if __name__ == '__main__':
    system_ini = ReadSystemIni()

    ini = ReadUserIni(system_ini.get_user_data_name("user2"))
    print(ini.get_file_path("excel"))