changeset 125:c6a41a60afc0

configuration/configuration.py
author Jeff Hammel <jhammel@mozilla.com>
date Tue, 17 Sep 2013 23:22:23 -0700
parents 5db2844b8300
children 82151d79e117
files configuration/configuration.py
diffstat 1 files changed, 14 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/configuration/configuration.py	Tue Sep 17 20:47:50 2013 -0700
+++ b/configuration/configuration.py	Tue Sep 17 23:22:23 2013 -0700
@@ -109,6 +109,7 @@
 
 __all__.extend([i.__class__.__name__ for i in configuration_providers])
 
+
 ### optparse interface
 
 class ConfigurationOption(optparse.Option):
@@ -240,6 +241,13 @@
     load_option = 'load' # where to put the load option
     load_help = "load configuration from a file"
 
+    @classmethod
+    def parse(cls, args, *_args, **_kwargs):
+        """get the resultant config dictionary in a single call"""
+        conf = cls(*_args, **_kwargs)
+        conf.parse_args(*_args, **_kwargs)
+        return conf.config
+
     def __init__(self, configuration_providers=configuration_providers, types=types, load=None, dump='--dump', **parser_args):
 
         # sanity check
@@ -358,6 +366,12 @@
                 defaults[key] = value['default']
         return copy.deepcopy(defaults)
 
+    def get(self, key, default=None):
+        return self.config.get(key, default)
+
+    def __getitem__(self, key):
+        return self.config[key]
+
     def __call__(self, *args):
         """add items to configuration and check it"""
         # TODO: configuration should be locked after this is called