summaryrefslogtreecommitdiff
path: root/util.py
blob: 4596e8aa9db71242b647016077ea337a9f3a471b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# vim: set filencoding=utf8
"""
Exchange Proxy Utility Functions

@author: Mike Crute (mcrute@ag.com)
@organization: American Greetings Interactive
@date: February 15, 2010
"""

from collections import defaultdict
from ConfigParser import ConfigParser


def config_dict(config_file):
    """
    Load a ConfigParser config as a dictionary. Will also
    attempt to do simple stuff like convert ints.
    """
    config = ConfigParser()
    config.read(config_file)
    output = defaultdict(dict)

    for section in config.sections():
        for key, value in config.items(section):
            if value.isdigit():
                value = int(value)

            output[section][key] = value

    return dict(output)