# -*- 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': '', 'onlinedc': True, 'template': 'template.html' } } 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