forked from scipy-conference/scipy_proceedings
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoptions.py
41 lines (30 loc) · 822 Bytes
/
options.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
"""
Configuration utilities.
"""
__all__ = ['options']
import os.path
import json
import codecs
import conf
toc_conf = conf.toc_conf
proc_conf = conf.proc_conf
def get_config():
config = cfg2dict(proc_conf)
config.update(cfg2dict(toc_conf))
return config
def cfg2dict(filename):
"""Return the content of a JSON config file as a dictionary.
"""
if not os.path.exists(filename):
print '*** Warning: %s does not exist.' % filename
return {}
return json.loads(codecs.open(filename, 'r', 'utf-8').read())
def dict2cfg(d, filename):
"""Write dictionary out to config file.
"""
json.dump(d, codecs.open(filename, 'w', 'utf-8'), ensure_ascii=False)
def mkdir_p(dir):
if os.path.isdir(dir):
return
os.makedirs(dir)
options = cfg2dict(proc_conf)