TeamspeakStats/tsstats/config.py

48 lines
1.0 KiB
Python
Raw Normal View History

# -*- coding: utf-8 -*-
try:
from configparser import ConfigParser
except ImportError:
from ConfigParser import ConfigParser
import logging
logger = logging.getLogger('tsstats')
DEFAULT_CONFIG = {
'General': {
'debug': False,
'log': '',
'output': 'output.html',
'idmap': '',
2016-08-10 16:45:07 -04:00
'onlinedc': True,
'template': 'template.html',
'datetimeformat': '%x %X %Z'
}
}
def load(path=None):
'''
parse config at `config_path`
:param config_path: path to config-file
:type config_path: str
:return: values of config
:rtype: tuple
'''
logger.debug('reading config')
config = ConfigParser()
# use this way to set defaults, because ConfigParser.read_dict
# is not available < 3.2
for section, items in DEFAULT_CONFIG.items():
if section not in config.sections():
config.add_section(section)
for key, value in items.items():
config.set(section, key, str(value))
if path:
config.read(path)
return config