Rev 5449: Implement the 'brz config' command. Read-only. in file:///home/vila/src/bzr/experimental/config/

Vincent Ladeuil v.ladeuil+lp at free.fr
Thu Sep 30 18:15:16 BST 2010


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

------------------------------------------------------------
revno: 5449
revision-id: v.ladeuil+lp at free.fr-20100930171515-k6ablrxpu2ei3ipz
parent: v.ladeuil+lp at free.fr-20100930111052-rue7ftm613c0v1mu
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: config-read
timestamp: Thu 2010-09-30 19:15:15 +0200
message:
  Implement the 'brz config' command. Read-only.
  
  * bzrlib/tests/blackbox/test_config.py:
  Add some test for 'bzr config'.
  
  * bzrlib/config.py:
  (BranchConfig.get_options_matching_regexp): Let's stop to pretend
  we can get a file name if the implementation doesn't provide it,
  the known cases are bBranchConfig and RemoteBranchConfig that will
  be modified anyway.
  (cmd_config): A simple command to display options known for a
  given directory.
-------------- next part --------------
=== modified file 'NEWS'
--- a/NEWS	2010-09-30 11:10:52 +0000
+++ b/NEWS	2010-09-30 17:15:15 +0000
@@ -22,6 +22,10 @@
 * Add ``annotate`` revision specifier, which selects the revision that
   introduced a specified line of a file.  (Aaron Bentley)
 
+* ``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. (Vincent Ladeuil)
+
 * ``bzr status`` now displays a summary of existing shelves after
   the other status information. This is done using a ``post_status``
   hook.

=== modified file 'bzrlib/builtins.py'
--- a/bzrlib/builtins.py	2010-09-24 12:53:00 +0000
+++ b/bzrlib/builtins.py	2010-09-30 17:15:15 +0000
@@ -6021,6 +6021,7 @@
     # be only called once.
     for (name, aliases, module_name) in [
         ('cmd_bundle_info', [], 'bzrlib.bundle.commands'),
+        ('cmd_config', ['conf'], 'bzrlib.config'),
         ('cmd_dpush', [], 'bzrlib.foreign'),
         ('cmd_version_info', [], 'bzrlib.cmd_version_info'),
         ('cmd_resolve', ['resolved'], 'bzrlib.conflicts'),

=== modified file 'bzrlib/config.py'
--- a/bzrlib/config.py	2010-09-30 11:10:52 +0000
+++ b/bzrlib/config.py	2010-09-30 17:15:15 +0000
@@ -65,6 +65,7 @@
 import os
 import sys
 
+from bzrlib import commands
 from bzrlib.decorators import needs_write_lock
 from bzrlib.lazy_import import lazy_import
 lazy_import(globals(), """
@@ -76,6 +77,7 @@
 import bzrlib
 from bzrlib import (
     atomicfile,
+    bzrdir,
     debug,
     errors,
     lockdir,
@@ -973,8 +975,17 @@
         if sections is None:
             sections = [('DEFAULT', branch_config._get_parser())]
         if file_name is None:
-            file_name = branch_config._config._transport.abspath(
-                branch_config._config._filename)
+            try:
+                file_name = self.file_name
+            except AttributeError:
+                # FIXME: Let's stop the horror right now, neither BranchConfig
+                # nor RemoteBranchConfig provides an easy way to get the file
+                # name which would be an url or an absolute path anyway. Let's
+                # punt for now until we decide how we want to report this piece
+                # of into to the user (preferably in a short form so 'bzr
+                # config var=value --in bazaar|location|branch remains easy to
+                # use) --vila 20100930
+                file_name = 'branch.conf'
         matches.extend(branch_config.get_options_matching_regexp(
                 name_re, sections, file_name))
         global_config = self._get_global_config()
@@ -1679,3 +1690,36 @@
         configobj.write(out_file)
         out_file.seek(0)
         self._transport.put_file(self._filename, out_file)
+
+
+class cmd_config(commands.Command):
+    __doc__ = """Display informations about configuration options.
+    """
+
+    aliases = ['conf']
+    takes_args = ['options?']
+
+    takes_options = [
+        'directory',
+        ]
+
+    @commands.display_command
+    def run(self, options=None, directory=None):
+        if options is None:
+            options = '*'
+        if directory is None:
+            directory = '.'
+        try:
+            (_, br, _) = bzrdir.BzrDir.open_containing_tree_or_branch(directory)
+            confs = [br.get_config()]
+        except errors.NotBranchError:
+            confs = [LocationConfig(directory), GlobalConfig()]
+        for c in confs:
+            matches = c.get_options_matching_glob(options)
+            cur_file_name = None
+            for (option_name, value, section, file_name) in matches:
+                if cur_file_name != file_name:
+                    self.outf.write('%s:\n' % (file_name,))
+                    cur_file_name = file_name
+                self.outf.write('  %s = %s\n' % (option_name, value))
+

=== modified file 'bzrlib/tests/blackbox/__init__.py'
--- a/bzrlib/tests/blackbox/__init__.py	2010-07-28 07:05:19 +0000
+++ b/bzrlib/tests/blackbox/__init__.py	2010-09-30 17:15:15 +0000
@@ -54,6 +54,7 @@
                      'bzrlib.tests.blackbox.test_clean_tree',
                      'bzrlib.tests.blackbox.test_command_encoding',
                      'bzrlib.tests.blackbox.test_commit',
+                     'bzrlib.tests.blackbox.test_config',
                      'bzrlib.tests.blackbox.test_conflicts',
                      'bzrlib.tests.blackbox.test_debug',
                      'bzrlib.tests.blackbox.test_deleted',

=== added file 'bzrlib/tests/blackbox/test_config.py'
--- a/bzrlib/tests/blackbox/test_config.py	1970-01-01 00:00:00 +0000
+++ b/bzrlib/tests/blackbox/test_config.py	2010-09-30 17:15:15 +0000
@@ -0,0 +1,80 @@
+# Copyright (C) 2010 Canonical Ltd
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+
+
+"""Black-box tests for bzr config."""
+
+import os
+
+from bzrlib import (
+    config,
+    tests,
+    )
+from bzrlib.tests import script
+
+
+class TestEmptyConfig(tests.TestCaseWithTransport):
+
+    def test_no_config(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)
+
+
+class TestConfigDisplay(tests.TestCaseWithTransport):
+
+    def setUp(self):
+        super(TestConfigDisplay, self).setUp()
+        # All the test can chose to test in a branch or outside of it
+        # (defaulting to location='.' by using '-d tree'. We create the 3
+        # canonnical configs and each test can set whatever option it sees fit.
+        self.tree = self.make_branch_and_tree('tree')
+        self.branch_config = config.BranchConfig(self.tree.branch)
+        self.locations_config = config.LocationConfig(self.tree.basedir)
+        self.global_config = config.GlobalConfig()
+
+    def test_global_config(self):
+        self.global_config.set_user_option('hello', 'world')
+        script.run_script(self, '''
+$ bzr config -d tree
+...bazaar.conf:
+  hello = world
+''')
+
+    def test_locations_config_for_branch(self):
+        self.locations_config.set_user_option('hello', 'world')
+        self.branch_config.set_user_option('hello', 'you')
+        script.run_script(self, '''
+$ bzr config -d tree
+...locations.conf:
+  hello = world
+...branch.conf:
+  hello = you
+''')
+
+    def test_locations_config_outside_branch(self):
+        self.global_config.set_user_option('hello', 'world')
+        self.locations_config.set_user_option('hello', 'world')
+        script.run_script(self, '''
+$ bzr config
+...bazaar.conf:
+  hello = world
+''')



More information about the bazaar-commits mailing list