read_user_ini.py 1.56 KB
Newer Older
shenjiamin 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:   ${PROJECT_NAME}
# FileName:      ${FILE_NAME}
# Author:        shen
# Datetime:     ${DATE} ${TIME}
# Description:
#
# ---------------------------------------------------------------------------
import configparser
import os.path

from APIAutoTest_shen_2 import log_decorator
from APIAutoTest_shen_2.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文件的路径
        ini_path = os.path.join(self.user_data_dir_path,"config.ini")
        # 创建Configparser对象
        self.conf = configparser.ConfigParser()
        # Configparser对象对象调用read方法读取ini文件
        self.conf.read(ini_path,encoding="utf-8")

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

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


if __name__ == '__main__':
    res = ReadUserIni("zs")
    print(res.get_table_name("name"))