Rev 5754: Basic store.set implementation. in file:///home/vila/src/bzr/experimental/config/
Vincent Ladeuil
v.ladeuil+lp at free.fr
Mon Apr 4 16:52:54 UTC 2011
At file:///home/vila/src/bzr/experimental/config/
------------------------------------------------------------
revno: 5754
revision-id: v.ladeuil+lp at free.fr-20110404165254-4r7a8mw4dzbu4mg8
parent: v.ladeuil+lp at free.fr-20110404153116-86oshhkw9nboow6z
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: config-store
timestamp: Mon 2011-04-04 18:52:54 +0200
message:
Basic store.set implementation.
-------------- next part --------------
=== modified file 'bzrlib/config.py'
--- a/bzrlib/config.py 2011-04-04 15:31:16 +0000
+++ b/bzrlib/config.py 2011-04-04 16:52:54 +0000
@@ -2123,6 +2123,15 @@
for section_name in cobj.sections:
yield section_name, dict(cobj[section_name])
+ def set(self, name, value, section_name=None):
+ # We need a loaded store
+ self.load()
+ if section_name is None:
+ section = self._config_obj
+ else:
+ section = self._config_obj.setdefault(section_name, {})
+ section[name] = 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-04-04 15:31:16 +0000
+++ b/bzrlib/tests/test_config.py 2011-04-04 16:52:54 +0000
@@ -1960,6 +1960,8 @@
self.assertEquals(('baz', {'foo': 'bar'}), sections[0])
def test_get_embedded_sections(self):
+ # A more complicated example (which also shows that section names and
+ # option names share the same name space...)
store = self.get_store('foo.conf', '''
foo=bar
l=1,2
@@ -1985,6 +1987,18 @@
'qux': {'foo_in_qux': 'quux'}}),
sections[3])
+ def test_set_in_default_section(self):
+ store = self.get_store('foo.conf', '')
+ store.set('foo', 'bar')
+ store.save()
+ self.assertFileEqual('foo = bar\n', 'foo.conf')
+
+ def test_set_in_named_section(self):
+ store = self.get_store('foo.conf', '')
+ store.set('foo', 'bar', 'baz')
+ store.save()
+ self.assertFileEqual('[baz]\nfoo = bar\n', 'foo.conf')
+
class TestConfigGetOptions(tests.TestCaseWithTransport, TestOptionsMixin):
More information about the bazaar-commits
mailing list