Mercurial > hg > configuration
comparison configuration/config.py @ 30:b27a7cb2dd5b
stub test for configuration providers
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Mon, 26 Mar 2012 17:05:02 -0700 |
parents | fadcc6ab51d4 |
children | 5571d1608cba |
comparison
equal
deleted
inserted
replaced
29:fadcc6ab51d4 | 30:b27a7cb2dd5b |
---|---|
57 def read(self, filename): | 57 def read(self, filename): |
58 return json.loads(file(filename).read()) | 58 return json.loads(file(filename).read()) |
59 def _write(self, fp, config): | 59 def _write(self, fp, config): |
60 fp.write(json.dumps(config), indent=self.indent, sort_keys=True) | 60 fp.write(json.dumps(config), indent=self.indent, sort_keys=True) |
61 # TODO: could use templates to get order down, etc | 61 # TODO: could use templates to get order down, etc |
62 configuration_providers.append(JSON) | 62 configuration_providers.append(JSON()) |
63 | 63 |
64 if yaml: | 64 if yaml: |
65 class YAML(object): | 65 class YAML(object): |
66 extensions = ['yml'] | 66 extensions = ['yml', 'yaml'] |
67 def read(self, filename): | 67 def read(self, filename): |
68 f = file(filename) | 68 f = file(filename) |
69 config = yaml.load(f) | 69 config = yaml.load(f) |
70 f.close() | 70 f.close() |
71 return config | 71 return config |
72 def _write(self, fp, config): | 72 def _write(self, fp, config): |
73 fp.write(yaml.dump(config)) | 73 fp.write(yaml.dump(config)) |
74 # TODO: could use templates to get order down, etc | 74 # TODO: could use templates to get order down, etc |
75 | 75 |
76 configuration_providers.append(YAML) | 76 configuration_providers.append(YAML()) |
77 | |
78 __all__.extend([i.__class__.__name__ for i in configuration_providers]) | |
77 | 79 |
78 ### plugins for option types | 80 ### plugins for option types |
79 ### TODO: this could use a bit of thought | 81 ### TODO: this could use a bit of thought |
80 def base_cli(name, value): | 82 def base_cli(name, value): |
81 # CLI arguments | 83 # CLI arguments |
273 """load configuration from a file""" | 275 """load configuration from a file""" |
274 # TODO: allow file object vs file name | 276 # TODO: allow file object vs file name |
275 | 277 |
276 if not format: | 278 if not format: |
277 extension = os.path.splitext(filename)[-1] | 279 extension = os.path.splitext(filename)[-1] |
278 |