read_ini.py 1.64 KB
Newer Older
duqing committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
# -*-coding:utf-8 -*- #
# ---------------------------------------------------------------------------
# ProjectName:   test61
# FileName:      read_ini.py
# Author:       lao_zhao
# Datetime:     2024/7/12 14:03
# Description:
# 
# ---------------------------------------------------------------------------
import configparser
import os.path


class ReadIni:
    def __init__(self, username):
        """获取ini文件的路径,并读取"""
        self.username_data_config_path = os.path.join(os.path.join(os.path.dirname(os.path.dirname(__file__)), "data_config"), username)
        ini_path = os.path.join(self.username_data_config_path, "config.ini")
        self.conf = configparser.ConfigParser()
        self.conf.read(ini_path, encoding="utf-8")

    def get_file_path(self, key):
        """根据key,获取file节点下文件的路径"""
        try:
            file_name = self.conf.get("file", key)
        except Exception as e:
            raise e
        else:
            return os.path.join(self.username_data_config_path, file_name)

    # def get_url(self, key):
    #     """根据key,获取被测系统的域名"""
    #     try:
    #         return self.conf.get("host", key)
    #     except Exception as e:
    #         raise e

    def get_table_name(self, key):
        """根据key获取工作表的名称"""
        try:
            return self.conf.get("table_name", key)
        except Exception as e:
            raise e
    #
    # def sql_connect_msg(self, key):
    #     """根据key,获取数据库的链接信息"""
    #     try:
    #         return self.conf.get("sql", key)
    #     except Exception as e:
    #         raise e