# -*-coding:utf-8 -*- #
# ---------------------------------------------------------------------------
# ProjectName:   test63_idea
# FileName:      Readuserini.py
# Author:       Jing
# Datetime:     2024/11/5 19:50
# Description:
# 
# ---------------------------------------------------------------------------
import os
import configparser
from v3 import log

class Readuserini:
    def __init__(self, user):
        self.data_path = os.path.join(os.path.dirname(os.path.dirname(__file__)), "data")
        self.user_ini = os.path.join(self.data_path, user)
        ini_path = os.path.join(self.user_ini, "config.ini")

        self.conf = configparser.ConfigParser()
        res = self.conf.read(ini_path, encoding="utf-8")
        if not res:
            log.error(f"读取ini文件失败，读取的用户文件是{user}，对应的文件路径是{ini_path}")
            raise ValueError("用户文件路径存在问题")


    def get_file_path(self, key):
        log.info(f"获取file节点下的key对应的文件名称，传入的参数是{key}")
        try:
            file_name = self.conf.get("file", key)
        except Exception as e:
            log.error(f'文件名Key有问题，具体错误为{e}，错误类型是{type(e)}')
            raise e
        else:
            file_path = os.path.join(self.user_ini, file_name)
            return file_path

    def get_table_name(self, key):
        log.info(f"获取table节点下的key对应的工作表名称，传入的参数是{key}")
        try:
            table_name = self.conf.get("table", key)
        except Exception as e:
            log.error(f'表名Key有问题，具体错误为{e}，错误类型是{type(e)}')
        else:
            return table_name



if __name__ == '__main__':
    ini = Readuserini("lisi")