diff options
Diffstat (limited to 'util.py')
-rw-r--r-- | util.py | 31 |
1 files changed, 31 insertions, 0 deletions
@@ -0,0 +1,31 @@ | |||
1 | # vim: set filencoding=utf8 | ||
2 | """ | ||
3 | Exchange Proxy Utility Functions | ||
4 | |||
5 | @author: Mike Crute (mcrute@ag.com) | ||
6 | @organization: American Greetings Interactive | ||
7 | @date: February 15, 2010 | ||
8 | """ | ||
9 | |||
10 | from collections import defaultdict | ||
11 | from ConfigParser import ConfigParser | ||
12 | |||
13 | |||
14 | def config_dict(config_file): | ||
15 | """ | ||
16 | Load a ConfigParser config as a dictionary. Will also | ||
17 | attempt to do simple stuff like convert ints. | ||
18 | """ | ||
19 | config = ConfigParser() | ||
20 | config.read(config_file) | ||
21 | output = defaultdict(dict) | ||
22 | |||
23 | for section in config.sections(): | ||
24 | for key, value in config.items(section): | ||
25 | if value.isdigit(): | ||
26 | value = int(value) | ||
27 | |||
28 | output[section][key] = value | ||
29 | |||
30 | return dict(output) | ||
31 | |||