# -*-coding:utf-8 -*- #
# ---------------------------------------------------------------------------
# ProjectName:   Selenium_Project
# FileName:      readini.py
# Author:       xxxxxxx
# Datetime:     2024/5/20 18:42
# Description:
# 命名规范：文件名全小写+下划线，类名大驼峰，方法和变量小写+下划线连接，
# 常量大写，变量和常量用名词，方法用动词
# ---------------------------------------------------------------------------
import configparser
import os

from api_test_0520 import log_decorator


class ReadIni:
    @log_decorator
    def __init__(self):
        self.config_path = os.path.join(os.path.dirname(os.path.dirname(__file__)), "data_config")
        ini_file_path = os.path.join(self.config_path, "config.ini")
        self.conf = configparser.ConfigParser()
        self.conf.read(ini_file_path, encoding="utf-8")

    @log_decorator
    def get_file_path(self, key, username="user_01"):
        try:
            value = self.conf.get("file", key)
        except Exception as e:
            print(e)
            raise e
        else:
            username_dir = os.path.join(self.config_path, username)
            return os.path.join(username_dir, value)

    @log_decorator
    def get_table_name(self, key):
        try:
            value = self.conf.get("worksheet", key)
        except Exception as e:
            print(e)
            raise e
        else:
            return value

    @log_decorator
    def get_host(self, key):
        try:
            value = self.conf.get("host", key)
        except Exception as e:
            print(e)
            raise e
        else:
            return value

    @log_decorator
    def get_db_data(self, key):
        try:
            value = self.conf.get("db", key)
        except Exception as e:
            print(e)
            raise e
        else:
            return value