Rev 5530: (vila) Display only the active value when a single option is provided to in file:///home/pqm/archives/thelove/bzr/%2Btrunk/
Canonical.com Patch Queue Manager
pqm at pqm.ubuntu.com
Sat Nov 6 18:13:48 GMT 2010
At file:///home/pqm/archives/thelove/bzr/%2Btrunk/
------------------------------------------------------------
revno: 5530 [merge]
revision-id: pqm at pqm.ubuntu.com-20101106181343-uprmjr9pyh43zw1e
parent: pqm at pqm.ubuntu.com-20101106163647-vg3eg5y6huqmv6c2
parent: v.ladeuil+lp at free.fr-20101106170942-rfe9b5bo2a7879cb
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Sat 2010-11-06 18:13:43 +0000
message:
(vila) Display only the active value when a single option is provided to
``bzr config``. (Vincent Ladeuil)
modified:
bzrlib/config.py config.py-20051011043216-070c74f4e9e338e8
bzrlib/tests/blackbox/test_config.py test_config.py-20100927150753-x6rf54uibd08r636-1
bzrlib/tests/test_config.py testconfig.py-20051011041908-742d0c15d8d8c8eb
doc/en/release-notes/bzr-2.3.txt NEWS-20050323055033-4e00b5db738777ff
doc/en/whats-new/whats-new-in-2.3.txt whatsnewin2.3.txt-20100818072501-x2h25r7jbnknvy30-1
=== modified file 'bzrlib/config.py'
--- a/bzrlib/config.py 2010-10-15 09:34:33 +0000
+++ b/bzrlib/config.py 2010-11-05 11:13:05 +0000
@@ -1772,17 +1772,20 @@
class cmd_config(commands.Command):
__doc__ = """Display, set or remove a configuration option.
- Display the MATCHING configuration options mentioning their scope (the
- configuration file they are defined in). The active value that bzr will
- take into account is the first one displayed.
+ Display the active value for a given option.
+
+ If --all is specified, NAME is interpreted as a regular expression and all
+ matching options are displayed mentioning their scope. The active value
+ that bzr will take into account is the first one displayed for each option.
+
+ If no NAME is given, --all .* is implied.
Setting a value is achieved by using name=value without spaces. The value
is set in the most relevant scope and can be checked by displaying the
option again.
"""
- aliases = ['conf']
- takes_args = ['matching?']
+ takes_args = ['name?']
takes_options = [
'directory',
@@ -1791,27 +1794,43 @@
commands.Option('scope', help='Reduce the scope to the specified'
' configuration file',
type=unicode),
+ commands.Option('all',
+ help='Display all the defined values for the matching options.',
+ ),
commands.Option('remove', help='Remove the option from'
' the configuration file'),
]
@commands.display_command
- def run(self, matching=None, directory=None, scope=None, remove=False):
+ def run(self, name=None, all=False, directory=None, scope=None,
+ remove=False):
if directory is None:
directory = '.'
directory = urlutils.normalize_url(directory)
- if matching is None:
- self._show_config('*', directory)
+ if remove and all:
+ raise errors.BzrError(
+ '--all and --remove are mutually exclusive.')
+ elif remove:
+ # Delete the option in the given scope
+ self._remove_config_option(name, directory, scope)
+ elif name is None:
+ # Defaults to all options
+ self._show_matching_options('.*', directory, scope)
else:
- if remove:
- self._remove_config_option(matching, directory, scope)
+ try:
+ name, value = name.split('=', 1)
+ except ValueError:
+ # Display the option(s) value(s)
+ if all:
+ self._show_matching_options(name, directory, scope)
+ else:
+ self._show_value(name, directory, scope)
else:
- pos = matching.find('=')
- if pos == -1:
- self._show_config(matching, directory)
- else:
- self._set_config_option(matching[:pos], matching[pos+1:],
- directory, scope)
+ if all:
+ raise errors.BzrError(
+ 'Only one option can be set.')
+ # Set the option value
+ self._set_config_option(name, value, directory, scope)
def _get_configs(self, directory, scope=None):
"""Iterate the configurations specified by ``directory`` and ``scope``.
@@ -1838,17 +1857,34 @@
yield LocationConfig(directory)
yield GlobalConfig()
- def _show_config(self, matching, directory):
- # Turn the glob into a regexp
- matching_re = re.compile(fnmatch.translate(matching))
+ def _show_value(self, name, directory, scope):
+ displayed = False
+ for c in self._get_configs(directory, scope):
+ if displayed:
+ break
+ for (oname, value, section, conf_id) in c._get_options():
+ if name == oname:
+ # Display only the first value and exit
+ self.outf.write('%s\n' % (value))
+ displayed = True
+ break
+ if not displayed:
+ raise errors.NoSuchConfigOption(name)
+
+ def _show_matching_options(self, name, directory, scope):
+ name = re.compile(name)
+ # We want any error in the regexp to be raised *now* so we need to
+ # avoid the delay introduced by the lazy regexp.
+ name._compile_and_collapse()
cur_conf_id = None
- for c in self._get_configs(directory):
- for (name, value, section, conf_id) in c._get_options():
- if matching_re.search(name):
+ for c in self._get_configs(directory, scope):
+ for (oname, value, section, conf_id) in c._get_options():
+ if name.search(oname):
if cur_conf_id != conf_id:
+ # Explain where the options are defined
self.outf.write('%s:\n' % (conf_id,))
cur_conf_id = conf_id
- self.outf.write(' %s = %s\n' % (name, value))
+ self.outf.write(' %s = %s\n' % (oname, value))
def _set_config_option(self, name, value, directory, scope):
for conf in self._get_configs(directory, scope):
@@ -1858,6 +1894,9 @@
raise errors.NoSuchConfig(scope)
def _remove_config_option(self, name, directory, scope):
+ if name is None:
+ raise errors.BzrCommandError(
+ '--remove expects an option to remove.')
removed = False
for conf in self._get_configs(directory, scope):
for (section_name, section, conf_id) in conf._get_sections():
=== modified file 'bzrlib/tests/blackbox/test_config.py'
--- a/bzrlib/tests/blackbox/test_config.py 2010-10-15 07:41:12 +0000
+++ b/bzrlib/tests/blackbox/test_config.py 2010-11-05 11:13:05 +0000
@@ -31,19 +31,42 @@
class TestWithoutConfig(tests.TestCaseWithTransport):
- def test_no_config(self):
+ def test_config_all(self):
out, err = self.run_bzr(['config'])
self.assertEquals('', out)
self.assertEquals('', err)
- def test_all_variables_no_config(self):
- out, err = self.run_bzr(['config', '*'])
- self.assertEquals('', out)
- self.assertEquals('', err)
+ def test_remove_unknown_option(self):
+ self.run_bzr_error(['The "file" configuration option does not exist',],
+ ['config', '--remove', 'file'])
+
+ def test_all_remove_exclusive(self):
+ self.run_bzr_error(['--all and --remove are mutually exclusive.',],
+ ['config', '--remove', '--all'])
+
+ def test_all_set_exclusive(self):
+ self.run_bzr_error(['Only one option can be set.',],
+ ['config', '--all', 'hello=world'])
+
+ def test_remove_no_option(self):
+ self.run_bzr_error(['--remove expects an option to remove.',],
+ ['config', '--remove'])
def test_unknown_option(self):
self.run_bzr_error(['The "file" configuration option does not exist',],
- ['config', '--remove', 'file'])
+ ['config', 'file'])
+
+ def test_unexpected_regexp(self):
+ self.run_bzr_error(
+ ['The "\*file" configuration option does not exist',],
+ ['config', '*file'])
+
+ def test_wrong_regexp(self):
+ self.run_bzr_error(
+ ['Invalid pattern\(s\) found. "\*file" nothing to repeat',],
+ ['config', '--all', '*file'])
+
+
class TestConfigDisplay(tests.TestCaseWithTransport):
@@ -80,6 +103,34 @@
''')
+class TestConfigActive(tests.TestCaseWithTransport):
+
+ def setUp(self):
+ super(TestConfigActive, self).setUp()
+ _t_config.create_configs_with_file_option(self)
+
+ def test_active_in_locations(self):
+ script.run_script(self, '''\
+ $ bzr config -d tree file
+ locations
+ ''')
+
+ def test_active_in_bazaar(self):
+ script.run_script(self, '''\
+ $ bzr config -d tree --scope bazaar file
+ bazaar
+ ''')
+
+ def test_active_in_branch(self):
+ # We need to delete the locations definition that overrides the branch
+ # one
+ script.run_script(self, '''\
+ $ bzr config -d tree --remove file
+ $ bzr config -d tree file
+ branch
+ ''')
+
+
class TestConfigSetOption(tests.TestCaseWithTransport):
def setUp(self):
@@ -93,7 +144,7 @@
def test_bazaar_config_outside_branch(self):
script.run_script(self, '''\
$ bzr config --scope bazaar hello=world
- $ bzr config -d tree hello
+ $ bzr config -d tree --all hello
bazaar:
hello = world
''')
@@ -101,7 +152,7 @@
def test_bazaar_config_inside_branch(self):
script.run_script(self, '''\
$ bzr config -d tree --scope bazaar hello=world
- $ bzr config -d tree hello
+ $ bzr config -d tree --all hello
bazaar:
hello = world
''')
@@ -109,7 +160,7 @@
def test_locations_config_inside_branch(self):
script.run_script(self, '''\
$ bzr config -d tree --scope locations hello=world
- $ bzr config -d tree hello
+ $ bzr config -d tree --all hello
locations:
hello = world
''')
@@ -117,7 +168,7 @@
def test_branch_config_default(self):
script.run_script(self, '''\
$ bzr config -d tree hello=world
- $ bzr config -d tree hello
+ $ bzr config -d tree --all hello
branch:
hello = world
''')
@@ -125,7 +176,7 @@
def test_branch_config_forcing_branch(self):
script.run_script(self, '''\
$ bzr config -d tree --scope branch hello=world
- $ bzr config -d tree hello
+ $ bzr config -d tree --all hello
branch:
hello = world
''')
@@ -144,7 +195,7 @@
def test_bazaar_config_outside_branch(self):
script.run_script(self, '''\
$ bzr config --scope bazaar --remove file
- $ bzr config -d tree file
+ $ bzr config -d tree --all file
locations:
file = locations
branch:
@@ -154,7 +205,7 @@
def test_bazaar_config_inside_branch(self):
script.run_script(self, '''\
$ bzr config -d tree --scope bazaar --remove file
- $ bzr config -d tree file
+ $ bzr config -d tree --all file
locations:
file = locations
branch:
@@ -164,7 +215,7 @@
def test_locations_config_inside_branch(self):
script.run_script(self, '''\
$ bzr config -d tree --scope locations --remove file
- $ bzr config -d tree file
+ $ bzr config -d tree --all file
branch:
file = branch
bazaar:
@@ -174,7 +225,7 @@
def test_branch_config_default(self):
script.run_script(self, '''\
$ bzr config -d tree --remove file
- $ bzr config -d tree file
+ $ bzr config -d tree --all file
branch:
file = branch
bazaar:
@@ -182,7 +233,7 @@
''')
script.run_script(self, '''\
$ bzr config -d tree --remove file
- $ bzr config -d tree file
+ $ bzr config -d tree --all file
bazaar:
file = bazaar
''')
@@ -190,7 +241,7 @@
def test_branch_config_forcing_branch(self):
script.run_script(self, '''\
$ bzr config -d tree --scope branch --remove file
- $ bzr config -d tree file
+ $ bzr config -d tree --all file
locations:
file = locations
bazaar:
@@ -198,7 +249,7 @@
''')
script.run_script(self, '''\
$ bzr config -d tree --remove file
- $ bzr config -d tree file
+ $ bzr config -d tree --all file
bazaar:
file = bazaar
''')
=== modified file 'bzrlib/tests/test_config.py'
--- a/bzrlib/tests/test_config.py 2010-10-13 08:01:36 +0000
+++ b/bzrlib/tests/test_config.py 2010-10-29 16:53:22 +0000
@@ -36,7 +36,10 @@
trace,
transport,
)
-from bzrlib.tests import features
+from bzrlib.tests import (
+ features,
+ scenarios,
+ )
from bzrlib.util.configobj import configobj
@@ -52,16 +55,7 @@
'config_section': '.'}),]
-def load_tests(standard_tests, module, loader):
- suite = loader.suiteClass()
-
- lc_tests, remaining_tests = tests.split_suite_by_condition(
- standard_tests, tests.condition_isinstance((
- TestLockableConfig,
- )))
- tests.multiply_tests(lc_tests, lockable_config_scenarios(), suite)
- suite.addTest(remaining_tests)
- return suite
+load_tests = scenarios.load_tests_apply_scenarios
sample_long_alias="log -r-15..-1 --line"
@@ -477,6 +471,8 @@
class TestLockableConfig(tests.TestCaseInTempDir):
+ scenarios = lockable_config_scenarios()
+
# Set by load_tests
config_class = None
config_args = None
@@ -1474,8 +1470,8 @@
def create_configs(test):
"""Create configuration files for a given test.
- This requires creating a tree (and populate the ``test.tree`` attribute and
- its associated branch and will populate the following attributes:
+ This requires creating a tree (and populate the ``test.tree`` attribute)
+ and its associated branch and will populate the following attributes:
- branch_config: A BranchConfig for the associated branch.
=== modified file 'doc/en/release-notes/bzr-2.3.txt'
--- a/doc/en/release-notes/bzr-2.3.txt 2010-11-06 15:32:00 +0000
+++ b/doc/en/release-notes/bzr-2.3.txt 2010-11-06 18:13:43 +0000
@@ -8,7 +8,6 @@
bzr 2.3b4
#########
-:Codename: Nirvana
:2.3.b4: NOT RELEASED YET
External Compatibility Breaks
@@ -27,6 +26,11 @@
.. Improvements to existing commands, especially improved performance
or memory usage, or better results.
+* ``bzr config <option>`` will now display only the value itself so scripts
+ can use it to query the currently active configuration. Displaying several
+ options matching a given regular expression is now controlled via the
+ ``--all`` option. (Vincent Ladeuil, bug #670251)
+
Bug Fixes
*********
=== modified file 'doc/en/whats-new/whats-new-in-2.3.txt'
--- a/doc/en/whats-new/whats-new-in-2.3.txt 2010-11-05 15:19:01 +0000
+++ b/doc/en/whats-new/whats-new-in-2.3.txt 2010-11-06 15:37:17 +0000
@@ -125,7 +125,8 @@
and configurations files. We've started working on unifying this and give
access to more options. The first step is a new ``bzr config`` command that
can be used to display the active configuration options in the current
-working tree or branch as well as the ability to set or remove an option.
+working tree or branch as well as the ability to set or remove an
+option. Scripts can also use it to get only the value for a given option.
Expected releases for the 2.3 series
************************************
More information about the bazaar-commits
mailing list