Rev 5744: Start implementing a config stack. in file:///home/vila/src/bzr/experimental/config/
Vincent Ladeuil
v.ladeuil+lp at free.fr
Thu Mar 31 15:06:49 UTC 2011
At file:///home/vila/src/bzr/experimental/config/
------------------------------------------------------------
revno: 5744
revision-id: v.ladeuil+lp at free.fr-20110331150649-dbcpw9y46fvgn1tb
parent: pqm at pqm.ubuntu.com-20110328161032-1a2n8l4z60xsvo50
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: config-stack
timestamp: Thu 2011-03-31 17:06:49 +0200
message:
Start implementing a config stack.
-------------- next part --------------
=== modified file 'bzrlib/config.py'
--- a/bzrlib/config.py 2011-02-25 12:12:39 +0000
+++ b/bzrlib/config.py 2011-03-31 15:06:49 +0000
@@ -1991,6 +1991,26 @@
self._transport.put_file(self._filename, out_file)
+class ConfigStack(object):
+ """A stack of configurations where an option can be defined"""
+
+ def __init__(self, config_list):
+ self.list = config_list
+ for c in self.list:
+ # Sanity check
+ if not hasattr(c, 'get'):
+ raise AssertionError("%r does not provide a 'get' method"
+ % (c,))
+
+ def get(self, name):
+ """Return the value from the first definition found in the list"""
+ for c in self.list:
+ value = c.get(name)
+ if value is not None:
+ break
+ return value
+
+
class cmd_config(commands.Command):
__doc__ = """Display, set or remove a configuration option.
=== modified file 'bzrlib/tests/test_config.py'
--- a/bzrlib/tests/test_config.py 2011-02-25 12:12:39 +0000
+++ b/bzrlib/tests/test_config.py 2011-03-31 15:06:49 +0000
@@ -1817,6 +1817,23 @@
self.assertIs(None, bzrdir_config.get_default_stack_on())
+class TestConfigStackGet(tests.TestCase):
+
+ def test_compatibility(self):
+ self.assertRaises(AssertionError, config.ConfigStack, [object()])
+
+ def test_single_config_get(self):
+ conf = dict(foo='bar')
+ conf_stack = config.ConfigStack([conf])
+ self.assertEquals('bar', conf_stack.get('foo'))
+
+ def test_get_first_definition(self):
+ conf1 = dict(foo='bar')
+ conf2 = dict(foo='baz')
+ conf_stack = config.ConfigStack([conf1, conf2])
+ self.assertEquals('bar', conf_stack.get('foo'))
+
+
class TestConfigGetOptions(tests.TestCaseWithTransport, TestOptionsMixin):
def setUp(self):
More information about the bazaar-commits
mailing list