~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/config.py

Start implementing a config stack.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1991
1991
        self._transport.put_file(self._filename, out_file)
1992
1992
 
1993
1993
 
 
1994
class ConfigStack(object):
 
1995
    """A stack of configurations where an option can be defined"""
 
1996
 
 
1997
    def __init__(self, config_list):
 
1998
        self.list = config_list
 
1999
        for c in self.list:
 
2000
            # Sanity check
 
2001
            if not hasattr(c, 'get'):
 
2002
                raise AssertionError("%r does not provide a 'get' method"
 
2003
                                     % (c,))
 
2004
 
 
2005
    def get(self, name):
 
2006
        """Return the value from the first definition found in the list"""
 
2007
        for c in self.list:
 
2008
            value = c.get(name)
 
2009
            if value is not None:
 
2010
                break
 
2011
        return value
 
2012
 
 
2013
 
1994
2014
class cmd_config(commands.Command):
1995
2015
    __doc__ = """Display, set or remove a configuration option.
1996
2016