2016-06-07 11:42:53 -04:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2016-05-08 15:32:37 -04:00
|
|
|
try:
|
2016-09-17 16:42:32 -04:00
|
|
|
from configparser import RawConfigParser
|
2016-05-08 15:32:37 -04:00
|
|
|
except ImportError:
|
2016-09-17 16:42:32 -04:00
|
|
|
from ConfigParser import RawConfigParser
|
2016-05-08 15:32:37 -04:00
|
|
|
|
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,
|
2017-02-27 06:39:31 -05:00
|
|
|
'debugstdout': False,
|
2016-08-06 15:36:17 -04:00
|
|
|
'log': '',
|
2016-09-22 09:35:39 -04:00
|
|
|
'output': 'tsstats.html',
|
2016-08-06 15:36:17 -04:00
|
|
|
'idmap': '',
|
2016-08-10 16:45:07 -04:00
|
|
|
'onlinedc': True,
|
2016-11-22 17:03:51 -05:00
|
|
|
'template': 'index.jinja2',
|
2016-11-11 12:40:52 -05:00
|
|
|
'datetimeformat': '%x %X %Z',
|
|
|
|
'onlinetimethreshold': -1
|
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-09-17 16:42:32 -04:00
|
|
|
config = RawConfigParser()
|
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
|