defget_view_config(section, option, option_default_val=None):"""
get view config data
:param section: config file section, mast be string
:param option: config file option, mast be string
:param option_default_val: When dose not get the config value, will set
default value if this params is not None
:return: config value
"""
file_path ="/etc/mass/mass-view-conf.ini"
conf = configparser.ConfigParser()
conf.read(file_path, encoding='utf-8')try:
result = conf.get(section, option)except configparser.NoSectionError as e:
logging.error('Dose not get section:{} in view config file,''NoSectionError: {}'.format(section, e))if option_default_val:
result = option_default_val
conf.add_section(section)
conf.set(section, option, option_default_val)withopen(file_path,'w')as f:
conf.write(f)else:
result =Noneexcept configparser.NoOptionError as e:
logging.error('Dose not get option:{} in the section:{},''NoOptionError: {}'.format(option, section, e))if option_default_val:
result = option_default_val
conf.set(section, option, option_default_val)withopen(file_path,'w')as f:
conf.write(f)else:
result =Nonereturn result