def get_config(config=None, config_file=None): _config = {} if not config else config config_file, config = parse_config_file(config_file) if not os.path.isfile(config_file): return _config config_dict = dict() for sec in config.sections(): try: _items = [(k, v) for k, v in config.items(sec) if k and v] config_dict[sec] = dict(_items) except TypeError: pass # Recursive/deep update. deep_update(config_dict, _config) return dict((k, v) for k, v in config_dict.items() if v is not None)
def get_config(config=None, config_file=None): _config = {} if not config else config config_file, config = parse_config_file(config_file) if not os.path.isfile(config_file): return _config config_dict = defaultdict(dict) for sec in config.sections(): try: for k, v in config.items(sec): if k is None or v is None: continue config_dict[sec][k] = v except TypeError: pass # Recursive/deep update. deep_update(config_dict, _config) return dict((k, v) for k, v in config_dict.items() if v is not None)