Rev 6136: (vila) Provide NameMatcher for config stores using arbitrary names for the in file:///home/pqm/archives/thelove/bzr/%2Btrunk/
Canonical.com Patch Queue Manager
pqm at pqm.ubuntu.com
Wed Sep 7 17:18:19 UTC 2011
At file:///home/pqm/archives/thelove/bzr/%2Btrunk/
------------------------------------------------------------
revno: 6136 [merge]
revision-id: pqm at pqm.ubuntu.com-20110907171815-23mzb6ugdi25bto1
parent: pqm at pqm.ubuntu.com-20110907162400-ej48d7m3wrzk0b3s
parent: v.ladeuil+lp at free.fr-20110907152139-wb368iwapfzqqtkm
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Wed 2011-09-07 17:18:15 +0000
message:
(vila) Provide NameMatcher for config stores using arbitrary names for the
sections. (Vincent Ladeuil)
modified:
bzrlib/config.py config.py-20051011043216-070c74f4e9e338e8
bzrlib/tests/test_config.py testconfig.py-20051011041908-742d0c15d8d8c8eb
doc/developers/configuration.txt configuration.txt-20110408142435-korjxxnskvq44sta-1
doc/en/release-notes/bzr-2.5.txt bzr2.5.txt-20110708125756-587p0hpw7oke4h05-1
=== modified file 'bzrlib/config.py'
--- a/bzrlib/config.py 2011-09-06 11:53:48 +0000
+++ b/bzrlib/config.py 2011-09-07 15:21:39 +0000
@@ -2891,8 +2891,8 @@
class SectionMatcher(object):
"""Select sections into a given Store.
- This intended to be used to postpone getting an iterable of sections from a
- store.
+ This is intended to be used to postpone getting an iterable of sections
+ from a store.
"""
def __init__(self, store):
@@ -2907,10 +2907,26 @@
if self.match(s):
yield s
- def match(self, secion):
+ def match(self, section):
+ """Does the proposed section match.
+
+ :param section: A Section object.
+
+ :returns: True if the section matches, False otherwise.
+ """
raise NotImplementedError(self.match)
+class NameMatcher(SectionMatcher):
+
+ def __init__(self, store, section_id):
+ super(NameMatcher, self).__init__(store)
+ self.section_id = section_id
+
+ def match(self, section):
+ return section.id == self.section_id
+
+
class LocationSection(Section):
def __init__(self, section, length, extra_path):
=== modified file 'bzrlib/tests/test_config.py'
--- a/bzrlib/tests/test_config.py 2011-09-06 11:53:48 +0000
+++ b/bzrlib/tests/test_config.py 2011-09-07 15:21:39 +0000
@@ -2624,9 +2624,6 @@
scenarios = [(key, {'get_store': builder}) for key, builder
in config.test_store_builder_registry.iteritems()]
- def setUp(self):
- super(TestReadonlyStore, self).setUp()
-
def test_building_delays_load(self):
store = self.get_store(self)
self.assertEquals(False, store.is_loaded())
@@ -3061,12 +3058,13 @@
# FIXME: It may be worth looking into removing the lock dir when it's not
# needed anymore and look at possible fallouts for concurrent lockers. This
# will matter if/when we use config files outside of bazaar directories
- # (.bazaar or .bzr) -- vila 20110-04-11
+ # (.bazaar or .bzr) -- vila 20110-04-111
class TestSectionMatcher(TestStore):
- scenarios = [('location', {'matcher': config.LocationMatcher})]
+ scenarios = [('location', {'matcher': config.LocationMatcher}),
+ ('id', {'matcher': config.NameMatcher}),]
def get_store(self, file_name):
return config.IniFileStore(self.get_readonly_transport(), file_name)
@@ -3181,6 +3179,35 @@
self.assertEquals(expected_location, matcher.location)
+class TestNameMatcher(TestStore):
+
+ def setUp(self):
+ super(TestNameMatcher, self).setUp()
+ self.store = config.IniFileStore(self.get_readonly_transport(),
+ 'foo.conf')
+ self.store._load_from_string('''
+[foo]
+option=foo
+[foo/baz]
+option=foo/baz
+[bar]
+option=bar
+''')
+
+ def get_matching_sections(self, name):
+ matcher = config.NameMatcher(self.store, name)
+ return list(matcher.get_sections())
+
+ def test_matching(self):
+ sections = self.get_matching_sections('foo')
+ self.assertLength(1, sections)
+ self.assertSectionContent(('foo', {'option': 'foo'}), sections[0])
+
+ def test_not_matching(self):
+ sections = self.get_matching_sections('baz')
+ self.assertLength(0, sections)
+
+
class TestStackGet(tests.TestCase):
# FIXME: This should be parametrized for all known Stack or dedicated
=== modified file 'doc/developers/configuration.txt'
--- a/doc/developers/configuration.txt 2011-08-19 14:10:32 +0000
+++ b/doc/developers/configuration.txt 2011-09-07 15:21:39 +0000
@@ -86,13 +86,25 @@
all data needed for the selection and uses it while processing the sections in
``get_sections``.
-Only ``ReadOnlySection`` objects are manipulated here but a ``SectionMatcher``
-can return dedicated ``Section`` to provide additional context (the
-``LocationSection`` add an ``extra_path`` attribute to implement the
-``appendpath`` policy for example).
+Only ``ReadOnlySection`` objects are manipulated here but a
+``SectionMatcher`` can return dedicated ``Section`` objects to provide
+additional context (the ``LocationSection`` add an ``extra_path`` attribute
+to implement the ``appendpath`` policy for example). If no sections match,
+an empty list is returned.
.. FIXME: Replace the appendpath example if/when it's deprecated ;)
+Specific section matchers can be implemented by overriding ``get_sections``
+or just ``match``.
+
+``bzrlib`` provides:
+
+* ``LocationMatcher(store, location)``: To select all sections that match
+ ``location``.
+
+* ``NameMatcher(store, unique_id)``: To select a single section matching
+ ``unique_id``.
+
Stacks
------
=== modified file 'doc/en/release-notes/bzr-2.5.txt'
--- a/doc/en/release-notes/bzr-2.5.txt 2011-09-07 09:57:43 +0000
+++ b/doc/en/release-notes/bzr-2.5.txt 2011-09-07 17:18:15 +0000
@@ -75,6 +75,10 @@
* ``config.Option`` can now declare ``default_from_env``, a list of
environment variables to get a default value from. (Vincent Ladeuil)
+* ``config.NameMatcher`` can be used to implement config stores and stacks
+ that need to provide specific option values for arbitrary unique IDs (svn
+ repository UUIDs, etc). (Vincent Ladeuil, #843638)
+
* New builtin ``bzr branches`` command, which lists all colocated branches
in a directory. (Jelmer Vernooij, #826820)
More information about the bazaar-commits
mailing list