Rev 6068: (vila) Implements list config options. (Vincent Ladeuil) in file:///home/pqm/archives/thelove/bzr/%2Btrunk/
Canonical.com Patch Queue Manager
pqm at pqm.ubuntu.com
Sat Aug 13 03:39:28 UTC 2011
At file:///home/pqm/archives/thelove/bzr/%2Btrunk/
------------------------------------------------------------
revno: 6068 [merge]
revision-id: pqm at pqm.ubuntu.com-20110813033924-w5vit9zjr8dmqe99
parent: pqm at pqm.ubuntu.com-20110812184836-5jv1u3ns0s74zsg0
parent: v.ladeuil+lp at free.fr-20110812140721-js88s3h388owol9o
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Sat 2011-08-13 03:39:24 +0000
message:
(vila) Implements list config options. (Vincent Ladeuil)
modified:
bzrlib/config.py config.py-20051011043216-070c74f4e9e338e8
bzrlib/tests/test_config.py testconfig.py-20051011041908-742d0c15d8d8c8eb
doc/en/release-notes/bzr-2.5.txt bzr2.5.txt-20110708125756-587p0hpw7oke4h05-1
=== modified file 'bzrlib/config.py'
--- a/bzrlib/config.py 2011-08-12 16:12:23 +0000
+++ b/bzrlib/config.py 2011-08-13 03:39:24 +0000
@@ -2317,6 +2317,22 @@
return int(unicode_str)
+def list_from_store(unicode_str):
+ # ConfigObj return '' instead of u''. Use 'str' below to catch all cases.
+ if isinstance(unicode_str, (str, unicode)):
+ if unicode_str:
+ # A single value, most probably the user forgot (or didn't care to
+ # add) the final ','
+ l = [unicode_str]
+ else:
+ # The empty string, convert to empty list
+ l = []
+ else:
+ # We rely on ConfigObj providing us with a list already
+ l = unicode_str
+ return l
+
+
class OptionRegistry(registry.Registry):
"""Register config options by their name.
=== modified file 'bzrlib/tests/test_config.py'
--- a/bzrlib/tests/test_config.py 2011-08-10 14:38:40 +0000
+++ b/bzrlib/tests/test_config.py 2011-08-12 14:07:21 +0000
@@ -3011,7 +3011,7 @@
self.assertRaises(errors.ConfigOptionValueError, self.conf.get, 'foo')
def register_integer_option(self, name, default):
- i = config.Option(name, default=default, help='A boolean.',
+ i = config.Option(name, default=default, help='An integer.',
from_unicode=config.int_from_store)
self.registry.register(i)
@@ -3038,6 +3038,48 @@
# No default value, so we should get None
self.assertEquals(None, self.conf.get('foo'))
+ def register_list_option(self, name, default):
+ l = config.Option(name, default=default, help='A list.',
+ from_unicode=config.list_from_store)
+ self.registry.register(l)
+
+ def test_get_with_list_not_defined_returns_default(self):
+ self.register_list_option('foo', [])
+ self.assertEquals([], self.conf.get('foo'))
+
+ def test_get_with_list_converter_nothing(self):
+ self.register_list_option('foo', [1])
+ self.conf.store._load_from_string('foo=')
+ self.assertEquals([], self.conf.get('foo'))
+
+ def test_get_with_list_converter_no_item(self):
+ self.register_list_option('foo', [1])
+ self.conf.store._load_from_string('foo=,')
+ self.assertEquals([], self.conf.get('foo'))
+
+ def test_get_with_list_converter_one_boolean(self):
+ self.register_list_option('foo', [1])
+ self.conf.store._load_from_string('foo=True')
+ # We get a list of one string
+ self.assertEquals(['True'], self.conf.get('foo'))
+
+ def test_get_with_list_converter_one_integer(self):
+ self.register_list_option('foo', [1])
+ self.conf.store._load_from_string('foo=2')
+ # We get a list of one string
+ self.assertEquals(['2'], self.conf.get('foo'))
+
+ def test_get_with_list_converter_one_string(self):
+ self.register_list_option('foo', ['foo'])
+ self.conf.store._load_from_string('foo=bar')
+ # We get a list of one string
+ self.assertEquals(['bar'], self.conf.get('foo'))
+
+ def test_get_with_list_converter_many_items(self):
+ self.register_list_option('foo', [1])
+ self.conf.store._load_from_string('foo=m,o,r,e')
+ self.assertEquals(['m', 'o', 'r', 'e'], self.conf.get('foo'))
+
class TestStackSet(TestStackWithTransport):
=== modified file 'doc/en/release-notes/bzr-2.5.txt'
--- a/doc/en/release-notes/bzr-2.5.txt 2011-08-12 10:54:51 +0000
+++ b/doc/en/release-notes/bzr-2.5.txt 2011-08-12 14:07:21 +0000
@@ -25,6 +25,11 @@
provided ``bool_from_store`` and ``int_from_store`` are used.
(Vincent Ladeuil)
+* A ``from_unicode`` parameter can be specified when registering a config
+ option. This implements boolean, integer and list config options when the
+ provided ``bool_from_store``, ``int_from_store`` and ``list_from_store``
+ are used for this parameter. (Vincent Ladeuil)
+
* Accessing a packaging branch on Launchpad (eg, ``lp:ubuntu/bzr``) now
checks to see if the most recent published source package version for
that project is present in the branch tags. This should help developers
More information about the bazaar-commits
mailing list