readConf.py 1.31 KB
# -*- coding: utf-8 -*-

# @Time    : 2021/7/16 10:36
# @Author  : Ljq
# @File    : readConf.py
# @Software: PyCharm

"""
配置文件读取
"""

import configparser
import os

class readConfig(object):
    ROBOT_LIBRARY_SCOPE = 'TEST CASE'
    ROBOT_LIBRARY_VERSION = '0.1'

    def __init__(self):
        self.conf = configparser.ConfigParser()
        self.evn_name = os.name
        self.file_name = r'test_config_hg.conf'
        self.relative_path = r'/config/marketConfig/'
        self.file_path = os.path.abspath(
            os.path.join(os.path.dirname(__file__), "../../")) + self.relative_path + self.file_name
        print(self.file_path)
        self.conf.read(self.file_path,encoding="utf-8")

    def returnSections(self):
        sections = self.conf.sections()
        print(sections)
        return sections

    def returnOptions(self,options):
        options = self.conf.options(options)
        print(options)
        return options

    def returnOptionsInfo(self,items):
        items = self.conf.items(items)
        print(items)

    def returnOptionsItems(self,options,items):
        value = self.conf.get(options,items)
        print(value)
        return value

    def ReturnFilePath(self):
        print(self.file_path)
        return self.file_path

# readConfig().returnOptionsItems("loginInfo","userName")