# HG changeset patch # User Jeff Hammel # Date 1332656062 25200 # Node ID dce954a3831fcc9c42ca6c14e881edcf0e5b8035 # Parent 7910b0ef0baba3eb422eccab8e2d5e196e392e57 more stubbing diff -r 7910b0ef0bab -r dce954a3831f configuration/config.py --- 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