178
221
def _get_signing_policy(self):
179
222
"""Template method to override signature creation policy."""
226
def expand_options(self, string, env=None):
227
"""Expand option references in the string in the configuration context.
229
:param string: The string containing option to expand.
231
:param env: An option dict defining additional configuration options or
232
overriding existing ones.
234
:returns: The expanded string.
236
return self._expand_options_in_string(string, env)
238
def _expand_options_in_list(self, slist, env=None, _ref_stack=None):
239
"""Expand options in a list of strings in the configuration context.
241
:param slist: A list of strings.
243
:param env: An option dict defining additional configuration options or
244
overriding existing ones.
246
:param _ref_stack: Private list containing the options being
247
expanded to detect loops.
249
:returns: The flatten list of expanded strings.
251
# expand options in each value separately flattening lists
254
value = self._expand_options_in_string(s, env, _ref_stack)
255
if isinstance(value, list):
261
def _expand_options_in_string(self, string, env=None, _ref_stack=None):
262
"""Expand options in the string in the configuration context.
264
:param string: The string to be expanded.
266
:param env: An option dict defining additional configuration options or
267
overriding existing ones.
269
:param _ref_stack: Private list containing the options being
270
expanded to detect loops.
272
:returns: The expanded string.
275
# Not much to expand there
277
if _ref_stack is None:
278
# What references are currently resolved (to detect loops)
280
if self.option_ref_re is None:
281
# We want to match the most embedded reference first (i.e. for
282
# '{{foo}}' we will get '{foo}',
283
# for '{bar{baz}}' we will get '{baz}'
284
self.option_ref_re = re.compile('({[^{}]+})')
286
# We need to iterate until no more refs appear ({{foo}} will need two
287
# iterations for example).
289
raw_chunks = self.option_ref_re.split(result)
290
if len(raw_chunks) == 1:
291
# Shorcut the trivial case: no refs
295
# Split will isolate refs so that every other chunk is a ref
297
for chunk in raw_chunks:
300
# Keep only non-empty strings (or we get bogus empty
301
# slots when a list value is involved).
306
if name in _ref_stack:
307
raise errors.OptionExpansionLoop(string, _ref_stack)
308
_ref_stack.append(name)
309
value = self._expand_option(name, env, _ref_stack)
311
raise errors.ExpandingUnknownOption(name, string)
312
if isinstance(value, list):
320
# Once a list appears as the result of an expansion, all
321
# callers will get a list result. This allows a consistent
322
# behavior even when some options in the expansion chain
323
# defined as strings (no comma in their value) but their
324
# expanded value is a list.
325
return self._expand_options_in_list(chunks, env, _ref_stack)
327
result = ''.join(chunks)
330
def _expand_option(self, name, env, _ref_stack):
331
if env is not None and name in env:
332
# Special case, values provided in env takes precedence over
336
# FIXME: This is a limited implementation, what we really need is a
337
# way to query the bzr config for the value of an option,
338
# respecting the scope rules (That is, once we implement fallback
339
# configs, getting the option value should restart from the top
340
# config, not the current one) -- vila 20101222
341
value = self.get_user_option(name, expand=False)
342
if isinstance(value, list):
343
value = self._expand_options_in_list(value, env, _ref_stack)
345
value = self._expand_options_in_string(value, env, _ref_stack)
181
348
def _get_user_option(self, option_name):
182
349
"""Template method to provide a user option."""
185
def get_user_option(self, option_name):
186
"""Get a generic option - no special process, no default."""
187
return self._get_user_option(option_name)
189
def get_user_option_as_bool(self, option_name):
352
def get_user_option(self, option_name, expand=None):
353
"""Get a generic option - no special process, no default.
355
:param option_name: The queried option.
357
:param expand: Whether options references should be expanded.
359
:returns: The value of the option.
362
expand = _get_expand_default_value()
363
value = self._get_user_option(option_name)
365
if isinstance(value, list):
366
value = self._expand_options_in_list(value)
367
elif isinstance(value, dict):
368
trace.warning('Cannot expand "%s":'
369
' Dicts do not support option expansion'
372
value = self._expand_options_in_string(value)
375
def get_user_option_as_bool(self, option_name, expand=None):
190
376
"""Get a generic option as a boolean - no special process, no default.
192
378
:return None if the option doesn't exist or its value can't be
193
379
interpreted as a boolean. Returns True or False otherwise.
195
s = self._get_user_option(option_name)
381
s = self.get_user_option(option_name, expand=expand)
197
383
# The option doesn't exist
1517
2085
return StringIO()
1519
2087
def _get_configobj(self):
1520
return ConfigObj(self._get_config_file(), encoding='utf-8')
2088
f = self._get_config_file()
2090
return ConfigObj(f, encoding='utf-8')
1522
2094
def _set_configobj(self, configobj):
1523
2095
out_file = StringIO()
1524
2096
configobj.write(out_file)
1525
2097
out_file.seek(0)
1526
2098
self._transport.put_file(self._filename, out_file)
2101
class Option(object):
2102
"""An option definition.
2104
The option *values* are stored in config files and found in sections.
2106
Here we define various properties about the option itself, its default
2107
value, in which config files it can be stored, etc (TBC).
2110
def __init__(self, name, default=None):
2112
self.default = default
2114
def get_default(self):
2120
option_registry = registry.Registry()
2123
option_registry.register(
2124
'editor', Option('editor'),
2125
help='The command called to launch an editor to enter a message.')
2128
class Section(object):
2129
"""A section defines a dict of option name => value.
2131
This is merely a read-only dict which can add some knowledge about the
2132
options. It is *not* a python dict object though and doesn't try to mimic
2136
def __init__(self, section_id, options):
2137
self.id = section_id
2138
# We re-use the dict-like object received
2139
self.options = options
2141
def get(self, name, default=None):
2142
return self.options.get(name, default)
2145
# Mostly for debugging use
2146
return "<config.%s id=%s>" % (self.__class__.__name__, self.id)
2149
_NewlyCreatedOption = object()
2150
"""Was the option created during the MutableSection lifetime"""
2153
class MutableSection(Section):
2154
"""A section allowing changes and keeping track of the original values."""
2156
def __init__(self, section_id, options):
2157
super(MutableSection, self).__init__(section_id, options)
2160
def set(self, name, value):
2161
if name not in self.options:
2162
# This is a new option
2163
self.orig[name] = _NewlyCreatedOption
2164
elif name not in self.orig:
2165
self.orig[name] = self.get(name, None)
2166
self.options[name] = value
2168
def remove(self, name):
2169
if name not in self.orig:
2170
self.orig[name] = self.get(name, None)
2171
del self.options[name]
2174
class Store(object):
2175
"""Abstract interface to persistent storage for configuration options."""
2177
readonly_section_class = Section
2178
mutable_section_class = MutableSection
2180
def is_loaded(self):
2181
"""Returns True if the Store has been loaded.
2183
This is used to implement lazy loading and ensure the persistent
2184
storage is queried only when needed.
2186
raise NotImplementedError(self.is_loaded)
2189
"""Loads the Store from persistent storage."""
2190
raise NotImplementedError(self.load)
2192
def _load_from_string(self, str_or_unicode):
2193
"""Create a store from a string in configobj syntax.
2195
:param str_or_unicode: A string representing the file content. This will
2196
be encoded to suit store needs internally.
2198
This is for tests and should not be used in production unless a
2199
convincing use case can be demonstrated :)
2201
raise NotImplementedError(self._load_from_string)
2204
"""Unloads the Store.
2206
This should make is_loaded() return False. This is used when the caller
2207
knows that the persistent storage has changed or may have change since
2210
raise NotImplementedError(self.unload)
2213
"""Saves the Store to persistent storage."""
2214
raise NotImplementedError(self.save)
2216
def external_url(self):
2217
raise NotImplementedError(self.external_url)
2219
def get_sections(self):
2220
"""Returns an ordered iterable of existing sections.
2222
:returns: An iterable of (name, dict).
2224
raise NotImplementedError(self.get_sections)
2226
def get_mutable_section(self, section_name=None):
2227
"""Returns the specified mutable section.
2229
:param section_name: The section identifier
2231
raise NotImplementedError(self.get_mutable_section)
2234
# Mostly for debugging use
2235
return "<config.%s(%s)>" % (self.__class__.__name__,
2236
self.external_url())
2239
class IniFileStore(Store):
2240
"""A config Store using ConfigObj for storage.
2242
:ivar transport: The transport object where the config file is located.
2244
:ivar file_name: The config file basename in the transport directory.
2246
:ivar _config_obj: Private member to hold the ConfigObj instance used to
2247
serialize/deserialize the config file.
2250
def __init__(self, transport, file_name):
2251
"""A config Store using ConfigObj for storage.
2253
:param transport: The transport object where the config file is located.
2255
:param file_name: The config file basename in the transport directory.
2257
super(IniFileStore, self).__init__()
2258
self.transport = transport
2259
self.file_name = file_name
2260
self._config_obj = None
2262
def is_loaded(self):
2263
return self._config_obj != None
2266
self._config_obj = None
2269
"""Load the store from the associated file."""
2270
if self.is_loaded():
2272
content = self.transport.get_bytes(self.file_name)
2273
self._load_from_string(content)
2275
def _load_from_string(self, str_or_unicode):
2276
"""Create a config store from a string.
2278
:param str_or_unicode: A string representing the file content. This will
2279
be utf-8 encoded internally.
2281
This is for tests and should not be used in production unless a
2282
convincing use case can be demonstrated :)
2284
if self.is_loaded():
2285
raise AssertionError('Already loaded: %r' % (self._config_obj,))
2286
co_input = StringIO(str_or_unicode.encode('utf-8'))
2288
# The config files are always stored utf8-encoded
2289
self._config_obj = ConfigObj(co_input, encoding='utf-8')
2290
except configobj.ConfigObjError, e:
2291
self._config_obj = None
2292
raise errors.ParseConfigError(e.errors, self.external_url())
2295
if not self.is_loaded():
2299
self._config_obj.write(out)
2300
self.transport.put_bytes(self.file_name, out.getvalue())
2302
def external_url(self):
2303
# FIXME: external_url should really accepts an optional relpath
2304
# parameter (bug #750169) :-/ -- vila 2011-04-04
2305
# The following will do in the interim but maybe we don't want to
2306
# expose a path here but rather a config ID and its associated
2307
# object </hand wawe>.
2308
return urlutils.join(self.transport.external_url(), self.file_name)
2310
def get_sections(self):
2311
"""Get the configobj section in the file order.
2313
:returns: An iterable of (name, dict).
2315
# We need a loaded store
2318
except errors.NoSuchFile:
2319
# If the file doesn't exist, there is no sections
2321
cobj = self._config_obj
2323
yield self.readonly_section_class(None, cobj)
2324
for section_name in cobj.sections:
2325
yield self.readonly_section_class(section_name, cobj[section_name])
2327
def get_mutable_section(self, section_name=None):
2328
# We need a loaded store
2331
except errors.NoSuchFile:
2332
# The file doesn't exist, let's pretend it was empty
2333
self._load_from_string('')
2334
if section_name is None:
2335
section = self._config_obj
2337
section = self._config_obj.setdefault(section_name, {})
2338
return self.mutable_section_class(section_name, section)
2341
# Note that LockableConfigObjStore inherits from ConfigObjStore because we need
2342
# unlockable stores for use with objects that can already ensure the locking
2343
# (think branches). If different stores (not based on ConfigObj) are created,
2344
# they may face the same issue.
2347
class LockableIniFileStore(IniFileStore):
2348
"""A ConfigObjStore using locks on save to ensure store integrity."""
2350
def __init__(self, transport, file_name, lock_dir_name=None):
2351
"""A config Store using ConfigObj for storage.
2353
:param transport: The transport object where the config file is located.
2355
:param file_name: The config file basename in the transport directory.
2357
if lock_dir_name is None:
2358
lock_dir_name = 'lock'
2359
self.lock_dir_name = lock_dir_name
2360
super(LockableIniFileStore, self).__init__(transport, file_name)
2361
self._lock = lockdir.LockDir(self.transport, self.lock_dir_name)
2363
def lock_write(self, token=None):
2364
"""Takes a write lock in the directory containing the config file.
2366
If the directory doesn't exist it is created.
2368
# FIXME: This doesn't check the ownership of the created directories as
2369
# ensure_config_dir_exists does. It should if the transport is local
2370
# -- vila 2011-04-06
2371
self.transport.create_prefix()
2372
return self._lock.lock_write(token)
2377
def break_lock(self):
2378
self._lock.break_lock()
2382
# We need to be able to override the undecorated implementation
2383
self.save_without_locking()
2385
def save_without_locking(self):
2386
super(LockableIniFileStore, self).save()
2389
# FIXME: global, bazaar, shouldn't that be 'user' instead or even
2390
# 'user_defaults' as opposed to 'user_overrides', 'system_defaults'
2391
# (/etc/bzr/bazaar.conf) and 'system_overrides' ? -- vila 2011-04-05
2393
# FIXME: Moreover, we shouldn't need classes for these stores either, factory
2394
# functions or a registry will make it easier and clearer for tests, focusing
2395
# on the relevant parts of the API that needs testing -- vila 20110503 (based
2396
# on a poolie's remark)
2397
class GlobalStore(LockableIniFileStore):
2399
def __init__(self, possible_transports=None):
2400
t = transport.get_transport(config_dir(),
2401
possible_transports=possible_transports)
2402
super(GlobalStore, self).__init__(t, 'bazaar.conf')
2405
class LocationStore(LockableIniFileStore):
2407
def __init__(self, possible_transports=None):
2408
t = transport.get_transport(config_dir(),
2409
possible_transports=possible_transports)
2410
super(LocationStore, self).__init__(t, 'locations.conf')
2413
class BranchStore(IniFileStore):
2415
def __init__(self, branch):
2416
super(BranchStore, self).__init__(branch.control_transport,
2418
self.branch = branch
2420
def lock_write(self, token=None):
2421
return self.branch.lock_write(token)
2424
return self.branch.unlock()
2428
# We need to be able to override the undecorated implementation
2429
self.save_without_locking()
2431
def save_without_locking(self):
2432
super(BranchStore, self).save()
2435
class SectionMatcher(object):
2436
"""Select sections into a given Store.
2438
This intended to be used to postpone getting an iterable of sections from a
2442
def __init__(self, store):
2445
def get_sections(self):
2446
# This is where we require loading the store so we can see all defined
2448
sections = self.store.get_sections()
2449
# Walk the revisions in the order provided
2454
def match(self, secion):
2455
raise NotImplementedError(self.match)
2458
class LocationSection(Section):
2460
def __init__(self, section, length, extra_path):
2461
super(LocationSection, self).__init__(section.id, section.options)
2462
self.length = length
2463
self.extra_path = extra_path
2465
def get(self, name, default=None):
2466
value = super(LocationSection, self).get(name, default)
2467
if value is not None:
2468
policy_name = self.get(name + ':policy', None)
2469
policy = _policy_value.get(policy_name, POLICY_NONE)
2470
if policy == POLICY_APPENDPATH:
2471
value = urlutils.join(value, self.extra_path)
2475
class LocationMatcher(SectionMatcher):
2477
def __init__(self, store, location):
2478
super(LocationMatcher, self).__init__(store)
2479
if location.startswith('file://'):
2480
location = urlutils.local_path_from_url(location)
2481
self.location = location
2483
def _get_matching_sections(self):
2484
"""Get all sections matching ``location``."""
2485
# We slightly diverge from LocalConfig here by allowing the no-name
2486
# section as the most generic one and the lower priority.
2487
no_name_section = None
2489
# Filter out the no_name_section so _iter_for_location_by_parts can be
2490
# used (it assumes all sections have a name).
2491
for section in self.store.get_sections():
2492
if section.id is None:
2493
no_name_section = section
2495
sections.append(section)
2496
# Unfortunately _iter_for_location_by_parts deals with section names so
2497
# we have to resync.
2498
filtered_sections = _iter_for_location_by_parts(
2499
[s.id for s in sections], self.location)
2500
iter_sections = iter(sections)
2501
matching_sections = []
2502
if no_name_section is not None:
2503
matching_sections.append(
2504
LocationSection(no_name_section, 0, self.location))
2505
for section_id, extra_path, length in filtered_sections:
2506
# a section id is unique for a given store so it's safe to iterate
2508
section = iter_sections.next()
2509
if section_id == section.id:
2510
matching_sections.append(
2511
LocationSection(section, length, extra_path))
2512
return matching_sections
2514
def get_sections(self):
2515
# Override the default implementation as we want to change the order
2516
matching_sections = self._get_matching_sections()
2517
# We want the longest (aka more specific) locations first
2518
sections = sorted(matching_sections,
2519
key=lambda section: (section.length, section.id),
2521
# Sections mentioning 'ignore_parents' restrict the selection
2522
for section in sections:
2523
# FIXME: We really want to use as_bool below -- vila 2011-04-07
2524
ignore = section.get('ignore_parents', None)
2525
if ignore is not None:
2526
ignore = ui.bool_from_string(ignore)
2529
# Finally, we have a valid section
2533
class Stack(object):
2534
"""A stack of configurations where an option can be defined"""
2536
def __init__(self, sections_def, store=None, mutable_section_name=None):
2537
"""Creates a stack of sections with an optional store for changes.
2539
:param sections_def: A list of Section or callables that returns an
2540
iterable of Section. This defines the Sections for the Stack and
2541
can be called repeatedly if needed.
2543
:param store: The optional Store where modifications will be
2544
recorded. If none is specified, no modifications can be done.
2546
:param mutable_section_name: The name of the MutableSection where
2547
changes are recorded. This requires the ``store`` parameter to be
2550
self.sections_def = sections_def
2552
self.mutable_section_name = mutable_section_name
2554
def get(self, name):
2555
"""Return the *first* option value found in the sections.
2557
This is where we guarantee that sections coming from Store are loaded
2558
lazily: the loading is delayed until we need to either check that an
2559
option exists or get its value, which in turn may require to discover
2560
in which sections it can be defined. Both of these (section and option
2561
existence) require loading the store (even partially).
2563
# FIXME: No caching of options nor sections yet -- vila 20110503
2565
# Ensuring lazy loading is achieved by delaying section matching (which
2566
# implies querying the persistent storage) until it can't be avoided
2567
# anymore by using callables to describe (possibly empty) section
2569
for section_or_callable in self.sections_def:
2570
# Each section can expand to multiple ones when a callable is used
2571
if callable(section_or_callable):
2572
sections = section_or_callable()
2574
sections = [section_or_callable]
2575
for section in sections:
2576
value = section.get(name)
2577
if value is not None:
2579
if value is not None:
2582
# If the option is registered, it may provide a default value
2584
opt = option_registry.get(name)
2589
value = opt.get_default()
2592
def _get_mutable_section(self):
2593
"""Get the MutableSection for the Stack.
2595
This is where we guarantee that the mutable section is lazily loaded:
2596
this means we won't load the corresponding store before setting a value
2597
or deleting an option. In practice the store will often be loaded but
2598
this allows helps catching some programming errors.
2600
section = self.store.get_mutable_section(self.mutable_section_name)
2603
def set(self, name, value):
2604
"""Set a new value for the option."""
2605
section = self._get_mutable_section()
2606
section.set(name, value)
2608
def remove(self, name):
2609
"""Remove an existing option."""
2610
section = self._get_mutable_section()
2611
section.remove(name)
2614
# Mostly for debugging use
2615
return "<config.%s(%s)>" % (self.__class__.__name__, id(self))
2618
class _CompatibleStack(Stack):
2619
"""Place holder for compatibility with previous design.
2621
This is intended to ease the transition from the Config-based design to the
2622
Stack-based design and should not be used nor relied upon by plugins.
2624
One assumption made here is that the daughter classes will all use Stores
2625
derived from LockableIniFileStore).
2627
It implements set() by re-loading the store before applying the
2628
modification and saving it.
2630
The long term plan being to implement a single write by store to save
2631
all modifications, this class should not be used in the interim.
2634
def set(self, name, value):
2637
super(_CompatibleStack, self).set(name, value)
2638
# Force a write to persistent storage
2642
class GlobalStack(_CompatibleStack):
2646
gstore = GlobalStore()
2647
super(GlobalStack, self).__init__([gstore.get_sections], gstore)
2650
class LocationStack(_CompatibleStack):
2652
def __init__(self, location):
2653
lstore = LocationStore()
2654
matcher = LocationMatcher(lstore, location)
2655
gstore = GlobalStore()
2656
super(LocationStack, self).__init__(
2657
[matcher.get_sections, gstore.get_sections], lstore)
2659
class BranchStack(_CompatibleStack):
2661
def __init__(self, branch):
2662
bstore = BranchStore(branch)
2663
lstore = LocationStore()
2664
matcher = LocationMatcher(lstore, branch.base)
2665
gstore = GlobalStore()
2666
super(BranchStack, self).__init__(
2667
[matcher.get_sections, bstore.get_sections, gstore.get_sections],
2669
self.branch = branch
2672
class cmd_config(commands.Command):
2673
__doc__ = """Display, set or remove a configuration option.
2675
Display the active value for a given option.
2677
If --all is specified, NAME is interpreted as a regular expression and all
2678
matching options are displayed mentioning their scope. The active value
2679
that bzr will take into account is the first one displayed for each option.
2681
If no NAME is given, --all .* is implied.
2683
Setting a value is achieved by using name=value without spaces. The value
2684
is set in the most relevant scope and can be checked by displaying the
2688
takes_args = ['name?']
2692
# FIXME: This should be a registry option so that plugins can register
2693
# their own config files (or not) -- vila 20101002
2694
commands.Option('scope', help='Reduce the scope to the specified'
2695
' configuration file',
2697
commands.Option('all',
2698
help='Display all the defined values for the matching options.',
2700
commands.Option('remove', help='Remove the option from'
2701
' the configuration file'),
2704
@commands.display_command
2705
def run(self, name=None, all=False, directory=None, scope=None,
2707
if directory is None:
2709
directory = urlutils.normalize_url(directory)
2711
raise errors.BzrError(
2712
'--all and --remove are mutually exclusive.')
2714
# Delete the option in the given scope
2715
self._remove_config_option(name, directory, scope)
2717
# Defaults to all options
2718
self._show_matching_options('.*', directory, scope)
2721
name, value = name.split('=', 1)
2723
# Display the option(s) value(s)
2725
self._show_matching_options(name, directory, scope)
2727
self._show_value(name, directory, scope)
2730
raise errors.BzrError(
2731
'Only one option can be set.')
2732
# Set the option value
2733
self._set_config_option(name, value, directory, scope)
2735
def _get_configs(self, directory, scope=None):
2736
"""Iterate the configurations specified by ``directory`` and ``scope``.
2738
:param directory: Where the configurations are derived from.
2740
:param scope: A specific config to start from.
2742
if scope is not None:
2743
if scope == 'bazaar':
2744
yield GlobalConfig()
2745
elif scope == 'locations':
2746
yield LocationConfig(directory)
2747
elif scope == 'branch':
2748
(_, br, _) = bzrdir.BzrDir.open_containing_tree_or_branch(
2750
yield br.get_config()
2753
(_, br, _) = bzrdir.BzrDir.open_containing_tree_or_branch(
2755
yield br.get_config()
2756
except errors.NotBranchError:
2757
yield LocationConfig(directory)
2758
yield GlobalConfig()
2760
def _show_value(self, name, directory, scope):
2762
for c in self._get_configs(directory, scope):
2765
for (oname, value, section, conf_id, parser) in c._get_options():
2767
# Display only the first value and exit
2769
# FIXME: We need to use get_user_option to take policies
2770
# into account and we need to make sure the option exists
2771
# too (hence the two for loops), this needs a better API
2773
value = c.get_user_option(name)
2774
# Quote the value appropriately
2775
value = parser._quote(value)
2776
self.outf.write('%s\n' % (value,))
2780
raise errors.NoSuchConfigOption(name)
2782
def _show_matching_options(self, name, directory, scope):
2783
name = re.compile(name)
2784
# We want any error in the regexp to be raised *now* so we need to
2785
# avoid the delay introduced by the lazy regexp.
2786
name._compile_and_collapse()
2789
for c in self._get_configs(directory, scope):
2790
for (oname, value, section, conf_id, parser) in c._get_options():
2791
if name.search(oname):
2792
if cur_conf_id != conf_id:
2793
# Explain where the options are defined
2794
self.outf.write('%s:\n' % (conf_id,))
2795
cur_conf_id = conf_id
2797
if (section not in (None, 'DEFAULT')
2798
and cur_section != section):
2799
# Display the section if it's not the default (or only)
2801
self.outf.write(' [%s]\n' % (section,))
2802
cur_section = section
2803
self.outf.write(' %s = %s\n' % (oname, value))
2805
def _set_config_option(self, name, value, directory, scope):
2806
for conf in self._get_configs(directory, scope):
2807
conf.set_user_option(name, value)
2810
raise errors.NoSuchConfig(scope)
2812
def _remove_config_option(self, name, directory, scope):
2814
raise errors.BzrCommandError(
2815
'--remove expects an option to remove.')
2817
for conf in self._get_configs(directory, scope):
2818
for (section_name, section, conf_id) in conf._get_sections():
2819
if scope is not None and conf_id != scope:
2820
# Not the right configuration file
2823
if conf_id != conf.config_id():
2824
conf = self._get_configs(directory, conf_id).next()
2825
# We use the first section in the first config where the
2826
# option is defined to remove it
2827
conf.remove_user_option(name, section_name)
2832
raise errors.NoSuchConfig(scope)
2834
raise errors.NoSuchConfigOption(name)
2838
# We need adapters that can build a Store or a Stack in a test context. Test
2839
# classes, based on TestCaseWithTransport, can use the registry to parametrize
2840
# themselves. The builder will receive a test instance and should return a
2841
# ready-to-use store or stack. Plugins that define new store/stacks can also
2842
# register themselves here to be tested against the tests defined in
2843
# bzrlib.tests.test_config. Note that the builder can be called multiple times
2844
# for the same tests.
2846
# The registered object should be a callable receiving a test instance
2847
# parameter (inheriting from tests.TestCaseWithTransport) and returning a Store
2849
test_store_builder_registry = registry.Registry()
2851
# The registered object should be a callable receiving a test instance
2852
# parameter (inheriting from tests.TestCaseWithTransport) and returning a Stack
2854
test_stack_builder_registry = registry.Registry()