mod_config.py 1 KB
Newer Older
haoyanbin's avatar
1  
haoyanbin committed
1 2 3 4 5 6 7 8 9 10 11 12 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 39 40 41 42 43 44 45 46
#!/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