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