Rev 5757: Stores don't implement set_option, they just provide a mutable section. in file:///home/vila/src/bzr/experimental/config/

Vincent Ladeuil v.ladeuil+lp at free.fr
Tue Apr 5 17:27:34 UTC 2011


At file:///home/vila/src/bzr/experimental/config/

------------------------------------------------------------
revno: 5757
revision-id: v.ladeuil+lp at free.fr-20110405172734-imy4dkxu6yix8k7f
parent: v.ladeuil+lp at free.fr-20110405150841-c9rj2kpcwrp7gfad
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: config-abstract-store
timestamp: Tue 2011-04-05 19:27:34 +0200
message:
  Stores don't implement set_option, they just provide a mutable section.
-------------- next part --------------
=== modified file 'bzrlib/config.py'
--- a/bzrlib/config.py	2011-04-05 15:08:41 +0000
+++ b/bzrlib/config.py	2011-04-05 17:27:34 +0000
@@ -2048,8 +2048,12 @@
         """
         raise NotImplementedError(self.get_sections)
 
-    def set_option(self, name, value, section_name=None):
-        raise NotImplementedError(self.set_option)
+    def get_mutable_section(self, section_name=None):
+        """Returns the specified mutable section.
+
+        :param section_name: The section identifier
+        """
+        raise NotImplementedError(self.get_mutable_section)
 
 
 class ConfigObjStore(Store):
@@ -2128,14 +2132,14 @@
         for section_name in cobj.sections:
             yield ReadOnlySection(section_name, cobj[section_name])
 
-    def set_option(self, name, value, section_name=None):
+    def get_mutable_section(self, 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
+        return MutableSection(section_name, section)
 
 
 class cmd_config(commands.Command):

=== modified file 'bzrlib/tests/test_config.py'
--- a/bzrlib/tests/test_config.py	2011-04-05 15:08:41 +0000
+++ b/bzrlib/tests/test_config.py	2011-04-05 17:27:34 +0000
@@ -2000,13 +2000,15 @@
 
     def test_set_option_in_default_section(self):
         store = self.get_store('foo.conf', '')
-        store.set_option('foo', 'bar')
+        section = store.get_mutable_section(None)
+        section.set('foo', 'bar')
         store.save()
         self.assertFileEqual('foo = bar\n', 'foo.conf')
 
     def test_set_option_in_named_section(self):
         store = self.get_store('foo.conf', '')
-        store.set_option('foo', 'bar', 'baz')
+        section = store.get_mutable_section('baz')
+        section.set('foo', 'bar')
         store.save()
         self.assertFileEqual('[baz]\nfoo = bar\n', 'foo.conf')
 



More information about the bazaar-commits mailing list