2016-03-18 20:08:10 +00:00
|
|
|
import ast, configparser
|
2016-03-16 12:49:28 +00:00
|
|
|
|
2016-03-16 12:57:57 +00:00
|
|
|
conffile = "config.cfg"
|
|
|
|
|
2016-03-16 12:49:28 +00:00
|
|
|
class SetupException(Exception):
|
|
|
|
def __str__(self):
|
|
|
|
return "Seems like config.cfg has not been created yet. Run setup.py to do so."
|
|
|
|
|
2016-07-20 17:30:51 +00:00
|
|
|
def getSetting(section, setting, exception = False):
|
|
|
|
try:
|
|
|
|
config = configparser.RawConfigParser()
|
|
|
|
config.read(conffile)
|
|
|
|
return config.get(section, setting)
|
|
|
|
except:
|
|
|
|
if exception:
|
|
|
|
raise SetupException()
|
|
|
|
return None
|
2016-03-16 12:49:28 +00:00
|
|
|
|
2016-07-20 17:30:51 +00:00
|
|
|
def getListSetting(section, setting, exception = False):
|
2016-03-18 20:08:10 +00:00
|
|
|
config = configparser.RawConfigParser()
|
|
|
|
config.read(conffile)
|
|
|
|
lit = config.get(section, setting)
|
2016-07-20 17:30:51 +00:00
|
|
|
if lit == None and exception:
|
|
|
|
raise SetupException()
|
2016-03-18 20:08:10 +00:00
|
|
|
return ast.literal_eval(lit)
|