2016-06-07 17:42:53 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2016-05-08 21:32:37 +02:00
|
|
|
try:
|
2016-09-17 22:42:32 +02:00
|
|
|
from configparser import RawConfigParser
|
2016-05-08 21:32:37 +02:00
|
|
|
except ImportError:
|
2016-09-17 22:42:32 +02:00
|
|
|
from ConfigParser import RawConfigParser
|
2016-05-08 21:32:37 +02:00
|
|
|
|
2016-05-21 22:59:32 +02:00
|
|
|
import logging
|
|
|
|
|
|
|
|
logger = logging.getLogger('tsstats')
|
|
|
|
|
2016-05-08 21:32:37 +02:00
|
|
|
|
2016-08-06 21:36:17 +02:00
|
|
|
DEFAULT_CONFIG = {
|
|
|
|
'General': {
|
|
|
|
'debug': False,
|
2017-02-27 12:39:31 +01:00
|
|
|
'debugstdout': False,
|
2016-08-06 21:36:17 +02:00
|
|
|
'log': '',
|
2016-09-22 15:35:39 +02:00
|
|
|
'output': 'tsstats.html',
|
2016-08-06 21:36:17 +02:00
|
|
|
'idmap': '',
|
2016-08-10 22:45:07 +02:00
|
|
|
'onlinedc': True,
|
2016-11-22 23:03:51 +01:00
|
|
|
'template': 'index.jinja2',
|
2016-11-11 18:40:52 +01:00
|
|
|
'datetimeformat': '%x %X %Z',
|
2017-05-20 01:00:12 +02:00
|
|
|
'onlinetimethreshold': -1,
|
|
|
|
'lastseenrelative': True
|
2016-08-06 21:36:17 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
def load(path=None):
|
2016-05-30 20:23:03 +02: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 22:59:32 +02:00
|
|
|
logger.debug('reading config')
|
2016-09-17 22:42:32 +02:00
|
|
|
config = RawConfigParser()
|
2016-08-06 21:36:17 +02: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 21:42:47 +02:00
|
|
|
if section not in config.sections():
|
2016-08-06 21:36:17 +02:00
|
|
|
config.add_section(section)
|
|
|
|
for key, value in items.items():
|
|
|
|
config.set(section, key, str(value))
|
|
|
|
if path:
|
|
|
|
config.read(path)
|
|
|
|
return config
|