Mercurial > piecrust2
comparison piecrust/configuration.py @ 3:f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
- Serving works, with debug window.
- Baking works, multi-threading, with dependency handling.
- Various things not implemented yet.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Sun, 10 Aug 2014 23:43:16 -0700 |
parents | 40fa08b261b9 |
children | 474c9882decf |
comparison
equal
deleted
inserted
replaced
2:40fa08b261b9 | 3:f485ba500df3 |
---|---|
4 | 4 |
5 | 5 |
6 logger = logging.getLogger(__name__) | 6 logger = logging.getLogger(__name__) |
7 | 7 |
8 | 8 |
9 class ConfigurationError(Exception): | |
10 pass | |
11 | |
12 | |
9 class Configuration(object): | 13 class Configuration(object): |
10 def __init__(self, values=None, validate=True): | 14 def __init__(self, values=None, validate=True): |
11 if values is not None: | 15 if values is not None: |
12 self.set_all(values, validate) | 16 self.setAll(values, validate) |
13 else: | 17 else: |
14 self._values = None | 18 self._values = None |
15 | 19 |
16 def set_all(self, values, validate=True): | 20 def setAll(self, values, validate=True): |
17 if validate: | 21 if validate: |
18 self._validateAll(values) | 22 self._validateAll(values) |
19 self._values = values | 23 self._values = values |
24 | |
25 def getAll(self): | |
26 return self.get() | |
20 | 27 |
21 def get(self, key_path=None): | 28 def get(self, key_path=None): |
22 self._ensureLoaded() | 29 self._ensureLoaded() |
23 if key_path is None: | 30 if key_path is None: |
24 return self._values | 31 return self._values |
71 | 78 |
72 def _validateValue(self, key_path, value): | 79 def _validateValue(self, key_path, value): |
73 return value | 80 return value |
74 | 81 |
75 | 82 |
76 def merge_dicts(source, merging, validator=None): | 83 def merge_dicts(source, merging, validator=None, *args): |
77 if validator is None: | 84 if validator is None: |
78 validator = lambda k, v: v | 85 validator = lambda k, v: v |
79 _recurse_merge_dicts(source, merging, None, validator) | 86 _recurse_merge_dicts(source, merging, None, validator) |
87 for other in args: | |
88 _recurse_merge_dicts(source, other, None, validator) | |
80 | 89 |
81 | 90 |
82 def _recurse_merge_dicts(local_cur, incoming_cur, parent_path, validator): | 91 def _recurse_merge_dicts(local_cur, incoming_cur, parent_path, validator): |
83 for k, v in incoming_cur.iteritems(): | 92 for k, v in incoming_cur.iteritems(): |
84 key_path = k | 93 key_path = k |
103 | 112 |
104 def parse_config_header(text): | 113 def parse_config_header(text): |
105 m = header_regex.match(text) | 114 m = header_regex.match(text) |
106 if m is not None: | 115 if m is not None: |
107 header = unicode(m.group('header')) | 116 header = unicode(m.group('header')) |
108 config = yaml.safe_load(header) | 117 config = yaml.load(header, Loader=yaml.BaseLoader) |
109 offset = m.end() | 118 offset = m.end() |
110 else: | 119 else: |
111 config = {} | 120 config = {} |
112 offset = 0 | 121 offset = 0 |
113 return config, offset | 122 return config, offset |