Mercurial > hg > configuration
changeset 6:dce954a3831f
more stubbing
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Sat, 24 Mar 2012 23:14:22 -0700 |
parents | 7910b0ef0bab |
children | 6e3cf8f05464 |
files | configuration/config.py |
diffstat | 1 files changed, 18 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/configuration/config.py Sat Mar 24 22:25:24 2012 -0700 +++ b/configuration/config.py Sat Mar 24 23:14:22 2012 -0700 @@ -20,6 +20,8 @@ except ImportError: yaml = None +__all__ = ['Configuration', 'configuration_providers'] + configuration_providers = [] if json: class JSON(object): @@ -30,25 +32,37 @@ class YAML(object): extensions = ['yml'] def read(self, filename): - pass + f = file(filename) + config = yaml.load(f) + f.close() + return config + configuration_providers.append(YAML) -__all__ = ['Configuration'] class Configuration(object): options = {} - def __init__(self): + def __init__(self, configuration_providers=configuration_providers): self.config = {} + self.configuration_providers = configuration_providers - def check(self): + def check(self, config): """check validity of configuration""" + # TODO: ensure options in configuration are in self.options + unknown_options = [] + + # + def __call__(self, *args): """add items to configuration and check it""" def add(self, config): """update configuration: not undoable""" + + self.check(config) + self.config.update(config) # TODO: option to extend; augment lists/dicts