-
Notifications
You must be signed in to change notification settings - Fork 34
/
configuration.py
48 lines (38 loc) · 1.51 KB
/
configuration.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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/local/bin/python
# -*- coding: utf-8 -*-
"""
Contains basic configuration information, especially path names to resource files
"""
__author__ = 'joscha'
__date__ = '03.12.12'
import os
import configparser
import warnings
if os.path.isfile('config.ini'):
filename = 'config.ini'
else:
filename = 'config.default.ini'
try:
config = configparser.ConfigParser()
with open(filename) as fp:
config.read_file(fp)
except OSError:
warnings.warn('Can not read config from inifile %s' % filename)
raise RuntimeError('Can not read config from inifile %s' % filename)
config['micropsi2']['version'] = "0.8-alpha6"
config['micropsi2']['apptitle'] = "MicroPsi"
homedir = config['micropsi2']['data_directory'].startswith('~')
if homedir:
data_path = os.path.expanduser(config['micropsi2']['data_directory'])
else:
data_path = config['micropsi2']['data_directory']
if 'logging' not in config:
config['logging'] = {}
for level in ['level_agent', 'level_system', 'level_world']:
if level not in config['logging']:
warnings.warn('logging level for %s not set in config.ini - defaulting to WARNING' % level)
config['logging'][level] = 'WARNING'
config.add_section('paths')
config['paths']['data_directory'] = os.path.join(os.path.dirname(__file__), data_path)
config['paths']['usermanager_path'] = os.path.join(os.path.dirname(__file__), 'resources', 'user-db.json')
config['paths']['server_settings_path'] = os.path.join(os.path.dirname(__file__), 'resources', 'server-config.json')