#!/usr/bin/env python # encoding: utf-8 import configparser import os import socket conf_file = '/conf/prod.conf' # conf_file = '/conf/dev.conf' def get_host_ip(): try: s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) s.connect(('8.8.8.8', 80)) ip = s.getsockname()[0] finally: s.close() return ip IP = get_host_ip() print(IP) # if IP == '172.19.0.11': # conf_file = '/conf/dev.conf' # elif IP == '10.0.0.136': # conf_file = '/conf/dev.conf' # else: # print('prod') # exit() # conf_file = '/conf/prod.conf' # 获取config配置文件 def getConfigOne(section, key): config = configparser.ConfigParser() path = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) config.read(path + conf_file) return config.get(section, key) # 获取config配置文件 def getConfig(): config = configparser.ConfigParser() path = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) config.read(path + conf_file) return config