forked from BinkyToo/CCDQuest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.py
26 lines (24 loc) · 784 Bytes
/
config.py
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
import ConfigParser
import os.path
import json
mainconfig = ConfigParser.RawConfigParser()
loaded = mainconfig.read("CCDQuest.cfg")
if not loaded:
raise Exception("Failed to load CCDQuest.cfg!")
def get(section, name, valuetype, default=None):
try:
value = mainconfig.get(section, name)
if valuetype is bool:
# ConfigParser.getboolean() does useful string parsing.
return mainconfig.getboolean(section, name)
else:
return valuetype(value)
except ValueError:
if default is None:
raise
else:
print "Warning: invalid value '%s' for [%s], %s" %(value, section, name)
except ConfigParser.Error:
if default is None:
raise
return valuetype(default)