read_basic_ini.py 1.43 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11
# ‐*‐coding:utf‐8 ‐*‐ #
# ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
# ProjectName: program01
# FileName: read_basic_ini.py
# Author: Conner-Lee
# Datetime: 2024/11/6 20:22
# Description: 
# ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
import configparser
import os.path

李江源 committed
12
from ApiAutoTest import log
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


class ReadBasicIni:

    def __init__(self):
        """读取ini文件"""
        self.data_config = os.path.join(os.path.dirname(os.path.dirname(__file__)), "data_config")
        ini_path = os.path.join(self.data_config, "basic_config.ini")
        self.conf = configparser.ConfigParser()
        self.conf.read(ini_path, encoding="utf-8")

    @log
    def get_host(self, key):
        """根据key获取域名"""
        return self.conf.get("host", key)

    @log
    def get_sql_connect(self, key):
        """根据key获取数据库连接信息"""
        return self.conf.get("sql", key)

if __name__ == "__main__":
    basic_ini = ReadBasicIni()
    print(basic_ini.get_host("bpm"))
    print(basic_ini.get_sql_connect("host"))
    print(basic_ini.get_sql_connect("port"))