settings.py
44 lines
| 867 B
| text/x-python
|
PythonLexer
/ boards / settings.py
neko259
|
r1153 | import configparser | ||
neko259
|
r1968 | CONFIG_DEFAULT_SETTINGS = 'boards/config/default_settings.ini' | ||
CONFIG_SETTINGS = 'boards/config/settings.ini' | ||||
neko259
|
r2002 | SECTION_FORMS = 'Forms' | ||
neko259
|
r2003 | SECTION_VIEW = 'View' | ||
neko259
|
r2008 | SECTION_EXTERNAL = 'External' | ||
neko259
|
r2011 | SECTION_VERSION = 'Version' | ||
neko259
|
r2002 | |||
VALUE_TRUE = 'true' | ||||
LIST_DELIMITER = ',' | ||||
DICT_DELIMITER = ':' | ||||
neko259
|
r1153 | config = configparser.ConfigParser() | ||
neko259
|
r1968 | config.read(CONFIG_DEFAULT_SETTINGS) | ||
config.read(CONFIG_SETTINGS) | ||||
neko259
|
r1153 | |||
neko259
|
r716 | |||
neko259
|
r1153 | def get(section, name): | ||
return config[section][name] | ||||
def get_int(section, name): | ||||
return int(get(section, name)) | ||||
def get_bool(section, name): | ||||
neko259
|
r2002 | return get(section, name) == VALUE_TRUE | ||
neko259
|
r1774 | |||
neko259
|
r1947 | |||
neko259
|
r1774 | def get_list_dict(section, name): | ||
str_dict = get(section, name) | ||||
neko259
|
r2002 | return [item.split(DICT_DELIMITER) for item in str_dict.split(LIST_DELIMITER)] | ||
neko259
|
r1774 | |||
neko259
|
r1968 | |||
neko259
|
r1993 | def get_list(section, name): | ||
str_list = get(section, name) | ||||
neko259
|
r2002 | return str_list.split(LIST_DELIMITER) | ||
neko259
|
r1993 | |||