Rev 5459: Turn get_options() and get_sections() into private methods because section handling is too messy and needs to be discussed and settled. in file:///home/vila/src/bzr/experimental/config/
Vincent Ladeuil
v.ladeuil+lp at free.fr
Mon Oct 4 18:37:15 BST 2010
At file:///home/vila/src/bzr/experimental/config/
------------------------------------------------------------
revno: 5459
revision-id: v.ladeuil+lp at free.fr-20101004173715-5hdx76tuiv3rdl3i
parent: v.ladeuil+lp at free.fr-20101004172452-unu266taysseifa4
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: config-modify
timestamp: Mon 2010-10-04 19:37:15 +0200
message:
Turn get_options() and get_sections() into private methods because section handling is too messy and needs to be discussed and settled.
-------------- next part --------------
=== modified file 'NEWS'
--- a/NEWS 2010-10-03 17:01:18 +0000
+++ b/NEWS 2010-10-04 17:37:15 +0000
@@ -24,8 +24,8 @@
* ``bzr config`` is a new command that displays the configuration options for
a given directory. It accepts a glob to match against multiple options at
- once. It can also be used to set a configuration option in any configuration
- file. (Vincent Ladeuil)
+ once. It can also be used to set or delete a configuration option in any
+ configuration file. (Vincent Ladeuil)
* ``bzr status`` now displays a summary of existing shelves after
the other status information. This is done using a ``post_status``
@@ -51,12 +51,6 @@
longer include the "log" information for tests which are considered to
be 'successes' (success, xfail, skip, etc) (John Arbash Meinel)
-* ``bzrlib.config.IniBasedConfig`` objects now implement ``get_options`` that
- permit querying them for the options defined and their values and
- ``get_sections()`` that return a list of (name, section) for the sections
- walked by get_user_option() and used by set_user_option().
- (Vincent Ladeuil)
-
Testing
*******
=== modified file 'bzrlib/config.py'
--- a/bzrlib/config.py 2010-10-04 17:24:52 +0000
+++ b/bzrlib/config.py 2010-10-04 17:37:15 +0000
@@ -450,7 +450,7 @@
"""Override this to define the section used by the config."""
return "DEFAULT"
- def get_sections(self, name=None):
+ def _get_sections(self, name=None):
"""Returns an iterator of the sections specified by ``name``.
:param name: The section name. If None is supplied, the default
@@ -468,7 +468,7 @@
# itself which holds the variables defined outside of any section.
yield (None, parser, self.id())
- def get_options(self, sections=None):
+ def _get_options(self, sections=None):
"""Return an ordered list of (name, value, section, config_id) tuples.
All options are returned with their associated value and the section
@@ -749,8 +749,8 @@
self._write_config_file()
- def get_sections(self, name=None):
- """See IniBasedConfig.get_sections()."""
+ def _get_sections(self, name=None):
+ """See IniBasedConfig._get_sections()."""
parser = self._get_parser()
# We don't give access to options defined outside of any section, we
# used the DEFAULT section by... default.
@@ -850,8 +850,8 @@
pass
return sections
- def get_sections(self, name=None):
- """See IniBasedConfig.get_sections()."""
+ def _get_sections(self, name=None):
+ """See IniBasedConfig._get_sections()."""
# We ignore the name here as the only sections handled are named with
# the location path and we don't expose embedded sections either.
parser = self._get_parser()
@@ -1022,16 +1022,16 @@
return value
return None
- def get_sections(self, name=None):
+ def _get_sections(self, name=None):
"""See IniBasedConfig.get_sections()."""
for source in self.option_sources:
- for section in source().get_sections(name):
+ for section in source()._get_sections(name):
yield section
- def get_options(self, sections=None):
+ def _get_options(self, sections=None):
opts = []
# First the locations options
- for option in self._get_location_config().get_options():
+ for option in self._get_location_config()._get_options():
yield option
# Then the branch options
branch_config = self._get_branch_data_config()
@@ -1044,7 +1044,7 @@
for (name, value) in section.iteritems():
yield (name, value, section_name, config_id)
# Then the global options
- for option in self._get_global_config().get_options():
+ for option in self._get_global_config()._get_options():
yield option
def set_user_option(self, name, value, store=STORE_BRANCH,
@@ -1835,7 +1835,7 @@
matching_re = re.compile(fnmatch.translate(matching))
cur_conf_id = None
for c in self._get_configs(directory):
- for (name, value, section, conf_id) in c.get_options():
+ for (name, value, section, conf_id) in c._get_options():
if matching_re.search(name):
if cur_conf_id != conf_id:
self.outf.write('%s:\n' % (conf_id,))
@@ -1852,7 +1852,7 @@
def _remove_config_option(self, name, directory, force):
removed = False
for conf in self._get_configs(directory, force):
- for (section_name, section, conf_id) in conf.get_sections():
+ for (section_name, section, conf_id) in conf._get_sections():
if force is not None and conf_id != force:
# Not the right configuration file
continue
@@ -1886,7 +1886,7 @@
removed = False
for conf in self._get_configs(directory, force):
trace.mutter('conf: %r' % (conf,))
- for (section_name, section, conf_id) in conf.get_sections():
+ for (section_name, section, conf_id) in conf._get_sections():
trace.mutter('section: %s, %r' % (section_name, section))
if name in section:
# We use the first section in the first config where the
=== modified file 'bzrlib/tests/test_config.py'
--- a/bzrlib/tests/test_config.py 2010-10-04 17:24:52 +0000
+++ b/bzrlib/tests/test_config.py 2010-10-04 17:37:15 +0000
@@ -1512,7 +1512,7 @@
create_configs(self)
def assertOptions(self, expected, conf):
- actual = list(conf.get_options())
+ actual = list(conf._get_options())
self.assertEqual(expected, actual)
# One variable in none of the above
@@ -1570,7 +1570,7 @@
create_configs_with_file_option(self)
def assertOptions(self, expected, conf):
- actual = list(conf.get_options())
+ actual = list(conf._get_options())
self.assertEqual(expected, actual)
def test_remove_in_locations(self):
@@ -1613,9 +1613,9 @@
:param name: An optional section name that will be passed to
get_sections().
"""
- sections = list(conf.get_sections(name))
+ sections = list(conf._get_sections(name))
self.assertLength(len(expected), sections)
- self.assertEqual(expected, [name for name, section in sections])
+ self.assertEqual(expected, [name for name, _, _ in sections])
def test_bazaar_default_section(self):
self.assertSectionNames(['DEFAULT'], self.bazaar_config)
More information about the bazaar-commits
mailing list