-
Notifications
You must be signed in to change notification settings - Fork 3
/
jsm_util.py
33 lines (31 loc) · 1.18 KB
/
jsm_util.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
from __future__ import print_function
def get_config(parameter, config, source=None, default=None):
"""
Gets the value of a parameter from the config variable.
It looks in the following order:
* a specific value that depends on the source
* a default value that does not depends on the source
* the default parameter entered in 'default'
"""
if source is None:
try:
return config[parameter]["default"]
except (KeyError, TypeError):
if default is not None:
return config.get(parameter, default)
else:
return config[parameter]
else:
if parameter in config.keys():
if "default" in config[parameter].keys():
return config[parameter].get(source, config[parameter]["default"])
else:
if default is not None:
return config[parameter].get(source, default)
else:
return config[parameter][source]
else:
if default is not None:
return config.get(parameter, default)
else:
return config[parameter]