Mercurial > hg > configuration
comparison configuration/configuration.py @ 84:34c13cde0255
move towards dict or items system
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Fri, 27 Apr 2012 13:39:13 -0700 |
parents | 490687e70723 |
children | 6067ae61cd17 |
comparison
equal
deleted
inserted
replaced
83:19834bc83d13 | 84:34c13cde0255 |
---|---|
228 """declarative configuration object""" | 228 """declarative configuration object""" |
229 | 229 |
230 options = {} # configuration basis | 230 options = {} # configuration basis |
231 | 231 |
232 def __init__(self, configuration_providers=configuration_providers, types=types, load=None, dump='--dump', **parser_args): | 232 def __init__(self, configuration_providers=configuration_providers, types=types, load=None, dump='--dump', **parser_args): |
233 | |
234 # sanity check | |
235 if isinstance(self.options, dict): | |
236 self.option_dict = self.options | |
237 elif isinstance(self.options, list): | |
238 # XXX could also be tuple, etc | |
239 self.option_dict = dict(self.options) | |
240 else: | |
241 raise NotImplementedError | |
233 | 242 |
234 # setup configuration | 243 # setup configuration |
235 self.config = {} | 244 self.config = {} |
236 self.configuration_providers = configuration_providers | 245 self.configuration_providers = configuration_providers |
237 self.types = types | 246 self.types = types |
268 ### methods for iteration | 277 ### methods for iteration |
269 ### TODO: make the class a real iterator | 278 ### TODO: make the class a real iterator |
270 | 279 |
271 def items(self): | 280 def items(self): |
272 # TODO: allow options to be a list of 2-tuples | 281 # TODO: allow options to be a list of 2-tuples |
273 return self.options.items() | 282 if isinstance(self.options, dict): |
283 return self.options.items() | |
284 return self.options | |
274 | 285 |
275 ### methods for validating configuration | 286 ### methods for validating configuration |
276 | 287 |
277 def check(self, config): | 288 def check(self, config): |
278 """ | 289 """ |