readConf.py 1.76 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'
        if self.evn_name == 'nt':
            self.relative_path = r'/config/marketConfig/'
            # # 本地调试路径
            self.file_path = os.path.abspath(os.path.join(os.getcwd(), "../..")) + self.relative_path+self.file_name
            # 本地main方法执行路径
#             self.file_path = os.path.abspath(os.path.join(os.getcwd(), "../")) + self.relative_path + self.file_name
        elif self.evn_name == 'posix':
            self.relative_path = r'/config/marketConfig/'
            self.file_path = os.path.abspath(os.path.join(os.getcwd())) + self.relative_path + self.file_name
            # self.file_path = os.getcwd()
        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")