import configparser
import os
import yaml

cf = configparser.ConfigParser()
curPath = os.path.abspath(os.path.dirname(__file__))
rootPath = rootPath = os.path.split(curPath)[0]

class confOP:
    def getConfValue(self, filename, section, option, type='string'):
        cf.read(filename)
        if (type == 'string'):
            value = cf.get(section, option)
        else:
            value = cf.getint(section, option)
        return value

    def getYamlValue(self, filename):
        """
        获取公共sql中的sql
        :param filename:
        :return:
        """
        file = os.path.join(rootPath, "data" + os.sep + filename)
        f = open(file, 'r', encoding='utf-8')
        cont = f.read()
        value = yaml.load(cont, Loader=yaml.FullLoader)
        f.close()
        return value

    def getBusiYamlValue(self, path, filename):
        """
        获取业务中的yaml文件数据
        :param path:
        :param filename:
        :return:
        """
        file = os.path.join(path, filename)
        f = open(file, 'r', encoding='utf-8')
        cont = f.read()
        value = yaml.load(cont, Loader=yaml.FullLoader)
        f.close()
        return value




