-
Notifications
You must be signed in to change notification settings - Fork 11
/
config.py
57 lines (45 loc) · 1.4 KB
/
config.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
49
50
51
52
53
54
55
56
57
from .exceptions import ConfigException
from deepmerge import Merger
class Config(dict):
"""
Config is a dictionary representing the configuration
values passed into the Uranium build.
config acts as a dictionary, and should be accessed as such.
"""
def set_defaults(self, default_dict):
"""
as a convenience for setting multiple defaults, set_defaults will set
keys that are not yet set to the values from default_dict.
.. code:: python
build.config.set_defaults({
"environment": "develop"
})
"""
_merger.merge(default_dict, self)
self.update(default_dict)
PROPER_FORMAT = """
a properly formatted config argument has at least one colon. the first colon will split the key and the value.
e.g. a:b -> a == key, b == value
""".strip()
def parse_confargs(config_arguments):
"""
given a list of configuration arguments, return
a config object.
"""
config = Config()
for arg in config_arguments:
if ":" not in arg:
raise ConfigException("configuration argument {0} is not properly formatted! {1}".format(
arg, PROPER_FORMAT
))
key, value = arg.split(":", 1)
config[key] = value
return config
_merger = Merger(
[
(list, ["override"]),
(dict, ["merge"])
],
["override"],
["override"]
)