Mercurial > hg > configuration
changeset 26:4fd88b1b08d5
ABC-ing configuration providers
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Mon, 26 Mar 2012 16:10:15 -0700 |
parents | b39e550402ea |
children | c6d966431498 |
files | configuration/config.py |
diffstat | 1 files changed, 21 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/configuration/config.py Mon Mar 26 15:55:05 2012 -0700 +++ b/configuration/config.py Mon Mar 26 16:10:15 2012 -0700 @@ -22,12 +22,33 @@ __all__ = ['Configuration', 'configuration_providers', 'types'] +### configuration providers for serialization/deserialization + configuration_providers = [] + +class ConfigurationProvider(object): + """ + abstract base class for configuration providers for + serialization/deserialization + """ + if json: class JSON(object): extensions = ['json'] def read(self, filename): return json.loads(file(filename).read()) + def write(self, config, filename): + if isinstance(filename, basestring): + f = file(filename, 'w') + newfile = True + else: + f = filename + newfile = False + try: + f.write(json.dumps(config)) + finally: + if newfile: + f.close() configuration_providers.append(JSON) if yaml: