-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathparseConfig.py
More file actions
executable file
·24 lines (18 loc) · 942 Bytes
/
parseConfig.py
File metadata and controls
executable file
·24 lines (18 loc) · 942 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import os, inspect, sys
if sys.version_info >= (3, 2):
from six.moves.configparser import ConfigParser as SafeConfigParser
else:
from six.moves.configparser import SafeConfigParser
from collections import defaultdict
def list_callback(option, opt, value, parser):
if value is None: return
setattr(parser.values, option.dest, value.split(','))
parser = SafeConfigParser()
# avoid converting input to lowercase
parser.optionxform = str
# first look in this script's dir, then current dir, then user $HOME (nonexistent files are skipped)
mypath = inspect.getsourcefile(list_callback).replace("parseConfig.py","")
candidates = [os.path.join(mypath,'.prodconfig'), os.path.join(os.getcwd(),'.prodconfig'), os.path.expanduser('~/.prodconfig')]
parser.read(candidates)
# convert to dict
parser_dict = defaultdict(lambda: defaultdict(str),{s:defaultdict(str,parser.items(s)) for s in parser.sections()})