Mercurial > hg > configuration
changeset 41:1bd4ddf2e81d
deserialization should work now
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Tue, 27 Mar 2012 10:51:34 -0700 |
parents | 056280e7a6ea |
children | 75886253ee73 |
files | configuration/config.py tests/unit.py |
diffstat | 2 files changed, 18 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/configuration/config.py Tue Mar 27 10:36:23 2012 -0700 +++ b/configuration/config.py Tue Mar 27 10:51:34 2012 -0700 @@ -29,6 +29,9 @@ class MissingValueException(Exception): """exception raised when a required value is missing""" +class ConfigurationProviderException(Exception): + """exception raised when a configuration provider is missing, etc""" + ### configuration providers for serialization/deserialization configuration_providers = [] @@ -325,7 +328,20 @@ """load configuration from a file""" # TODO: allow file object vs file name + # get the format if not format: - extension = os.path.splitext(filename)[-1] + format = self.filename2format(filename) + + # get the providers in some sensible order + providers = self.configuration_providers[:] + if format: + providers.sort(key=lambda x: int(format in x.extensions), reverse=True) - raise NotImplementedError("TODO") + # deserialize the data + for provider in providers: + try: + return provider.read(filename) + except: + continue + else: + raise ConfigurationProviderException("Could not load %s" % filename)