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
# We don't want to create a cycle here when the BranchStore becomes
2419
# part of an object (roughly a Stack, directly or indirectly) that is
2420
# an attribute of the branch object itself. Since the BranchStore
2421
# cannot exist without a branch, it's safe to make it a weakref.
2422
self.branch_ref = weakref.ref(branch)
2424
def _get_branch(self):
2425
b = self.branch_ref()
2427
# Programmer error, a branch store can't exist if the branch it
2428
# refers to is dead.
2429
raise AssertionError('Dead branch ref in %r' % (self,))
2432
def lock_write(self, token=None):
2433
return self._get_branch().lock_write(token)
2436
return self._get_branch().unlock()
2440
# We need to be able to override the undecorated implementation
2441
self.save_without_locking()
2443
def save_without_locking(self):
2444
super(BranchStore, self).save()
2447
class SectionMatcher(object):
2448
"""Select sections into a given Store.
2450
This intended to be used to postpone getting an iterable of sections from a
2454
def __init__(self, store):
2457
def get_sections(self):
2458
# This is where we require loading the store so we can see all defined
2460
sections = self.store.get_sections()
2461
# Walk the revisions in the order provided
2466
def match(self, secion):
2467
raise NotImplementedError(self.match)
2470
class LocationSection(Section):
2472
def __init__(self, section, length, extra_path):
2473
super(LocationSection, self).__init__(section.id, section.options)
2474
self.length = length
2475
self.extra_path = extra_path
2477
def get(self, name, default=None):
2478
value = super(LocationSection, self).get(name, default)
2479
if value is not None:
2480
policy_name = self.get(name + ':policy', None)
2481
policy = _policy_value.get(policy_name, POLICY_NONE)
2482
if policy == POLICY_APPENDPATH:
2483
value = urlutils.join(value, self.extra_path)
2487
class LocationMatcher(SectionMatcher):
2489
def __init__(self, store, location):
2490
super(LocationMatcher, self).__init__(store)
2491
if location.startswith('file://'):
2492
location = urlutils.local_path_from_url(location)
2493
self.location = location
2495
def _get_matching_sections(self):
2496
"""Get all sections matching ``location``."""
2497
# We slightly diverge from LocalConfig here by allowing the no-name
2498
# section as the most generic one and the lower priority.
2499
no_name_section = None
2501
# Filter out the no_name_section so _iter_for_location_by_parts can be
2502
# used (it assumes all sections have a name).
2503
for section in self.store.get_sections():
2504
if section.id is None:
2505
no_name_section = section
2507
sections.append(section)
2508
# Unfortunately _iter_for_location_by_parts deals with section names so
2509
# we have to resync.
2510
filtered_sections = _iter_for_location_by_parts(
2511
[s.id for s in sections], self.location)
2512
iter_sections = iter(sections)
2513
matching_sections = []
2514
if no_name_section is not None:
2515
matching_sections.append(
2516
LocationSection(no_name_section, 0, self.location))
2517
for section_id, extra_path, length in filtered_sections:
2518
# a section id is unique for a given store so it's safe to iterate
2520
section = iter_sections.next()
2521
if section_id == section.id:
2522
matching_sections.append(
2523
LocationSection(section, length, extra_path))
2524
return matching_sections
2526
def get_sections(self):
2527
# Override the default implementation as we want to change the order
2528
matching_sections = self._get_matching_sections()
2529
# We want the longest (aka more specific) locations first
2530
sections = sorted(matching_sections,
2531
key=lambda section: (section.length, section.id),
2533
# Sections mentioning 'ignore_parents' restrict the selection
2534
for section in sections:
2535
# FIXME: We really want to use as_bool below -- vila 2011-04-07
2536
ignore = section.get('ignore_parents', None)
2537
if ignore is not None:
2538
ignore = ui.bool_from_string(ignore)
2541
# Finally, we have a valid section
2545
class Stack(object):
2546
"""A stack of configurations where an option can be defined"""
2548
def __init__(self, sections_def, store=None, mutable_section_name=None):
2549
"""Creates a stack of sections with an optional store for changes.
2551
:param sections_def: A list of Section or callables that returns an
2552
iterable of Section. This defines the Sections for the Stack and
2553
can be called repeatedly if needed.
2555
:param store: The optional Store where modifications will be
2556
recorded. If none is specified, no modifications can be done.
2558
:param mutable_section_name: The name of the MutableSection where
2559
changes are recorded. This requires the ``store`` parameter to be
2562
self.sections_def = sections_def
2564
self.mutable_section_name = mutable_section_name
2566
def get(self, name):
2567
"""Return the *first* option value found in the sections.
2569
This is where we guarantee that sections coming from Store are loaded
2570
lazily: the loading is delayed until we need to either check that an
2571
option exists or get its value, which in turn may require to discover
2572
in which sections it can be defined. Both of these (section and option
2573
existence) require loading the store (even partially).
2575
# FIXME: No caching of options nor sections yet -- vila 20110503
2577
# Ensuring lazy loading is achieved by delaying section matching (which
2578
# implies querying the persistent storage) until it can't be avoided
2579
# anymore by using callables to describe (possibly empty) section
2581
for section_or_callable in self.sections_def:
2582
# Each section can expand to multiple ones when a callable is used
2583
if callable(section_or_callable):
2584
sections = section_or_callable()
2586
sections = [section_or_callable]
2587
for section in sections:
2588
value = section.get(name)
2589
if value is not None:
2591
if value is not None:
2594
# If the option is registered, it may provide a default value
2596
opt = option_registry.get(name)
2601
value = opt.get_default()
2604
def _get_mutable_section(self):
2605
"""Get the MutableSection for the Stack.
2607
This is where we guarantee that the mutable section is lazily loaded:
2608
this means we won't load the corresponding store before setting a value
2609
or deleting an option. In practice the store will often be loaded but
2610
this allows helps catching some programming errors.
2612
section = self.store.get_mutable_section(self.mutable_section_name)
2615
def set(self, name, value):
2616
"""Set a new value for the option."""
2617
section = self._get_mutable_section()
2618
section.set(name, value)
2620
def remove(self, name):
2621
"""Remove an existing option."""
2622
section = self._get_mutable_section()
2623
section.remove(name)
2626
# Mostly for debugging use
2627
return "<config.%s(%s)>" % (self.__class__.__name__, id(self))
2630
class _CompatibleStack(Stack):
2631
"""Place holder for compatibility with previous design.
2633
This is intended to ease the transition from the Config-based design to the
2634
Stack-based design and should not be used nor relied upon by plugins.
2636
One assumption made here is that the daughter classes will all use Stores
2637
derived from LockableIniFileStore).
2639
It implements set() by re-loading the store before applying the
2640
modification and saving it.
2642
The long term plan being to implement a single write by store to save
2643
all modifications, this class should not be used in the interim.
2646
def set(self, name, value):
2649
super(_CompatibleStack, self).set(name, value)
2650
# Force a write to persistent storage
2654
class GlobalStack(_CompatibleStack):
2658
gstore = GlobalStore()
2659
super(GlobalStack, self).__init__([gstore.get_sections], gstore)
2662
class LocationStack(_CompatibleStack):
2664
def __init__(self, location):
2665
lstore = LocationStore()
2666
matcher = LocationMatcher(lstore, location)
2667
gstore = GlobalStore()
2668
super(LocationStack, self).__init__(
2669
[matcher.get_sections, gstore.get_sections], lstore)
2671
class BranchStack(_CompatibleStack):
2673
def __init__(self, branch):
2674
bstore = BranchStore(branch)
2675
lstore = LocationStore()
2676
matcher = LocationMatcher(lstore, branch.base)
2677
gstore = GlobalStore()
2678
super(BranchStack, self).__init__(
2679
[matcher.get_sections, bstore.get_sections, gstore.get_sections],
2681
self.branch = branch
2684
class cmd_config(commands.Command):
2685
__doc__ = """Display, set or remove a configuration option.
2687
Display the active value for a given option.
2689
If --all is specified, NAME is interpreted as a regular expression and all
2690
matching options are displayed mentioning their scope. The active value
2691
that bzr will take into account is the first one displayed for each option.
2693
If no NAME is given, --all .* is implied.
2695
Setting a value is achieved by using name=value without spaces. The value
2696
is set in the most relevant scope and can be checked by displaying the
2700
takes_args = ['name?']
2704
# FIXME: This should be a registry option so that plugins can register
2705
# their own config files (or not) -- vila 20101002
2706
commands.Option('scope', help='Reduce the scope to the specified'
2707
' configuration file',
2709
commands.Option('all',
2710
help='Display all the defined values for the matching options.',
2712
commands.Option('remove', help='Remove the option from'
2713
' the configuration file'),
2716
@commands.display_command
2717
def run(self, name=None, all=False, directory=None, scope=None,
2719
if directory is None:
2721
directory = urlutils.normalize_url(directory)
2723
raise errors.BzrError(
2724
'--all and --remove are mutually exclusive.')
2726
# Delete the option in the given scope
2727
self._remove_config_option(name, directory, scope)
2729
# Defaults to all options
2730
self._show_matching_options('.*', directory, scope)
2733
name, value = name.split('=', 1)
2735
# Display the option(s) value(s)
2737
self._show_matching_options(name, directory, scope)
2739
self._show_value(name, directory, scope)
2742
raise errors.BzrError(
2743
'Only one option can be set.')
2744
# Set the option value
2745
self._set_config_option(name, value, directory, scope)
2747
def _get_configs(self, directory, scope=None):
2748
"""Iterate the configurations specified by ``directory`` and ``scope``.
2750
:param directory: Where the configurations are derived from.
2752
:param scope: A specific config to start from.
2754
if scope is not None:
2755
if scope == 'bazaar':
2756
yield GlobalConfig()
2757
elif scope == 'locations':
2758
yield LocationConfig(directory)
2759
elif scope == 'branch':
2760
(_, br, _) = bzrdir.BzrDir.open_containing_tree_or_branch(
2762
yield br.get_config()
2765
(_, br, _) = bzrdir.BzrDir.open_containing_tree_or_branch(
2767
yield br.get_config()
2768
except errors.NotBranchError:
2769
yield LocationConfig(directory)
2770
yield GlobalConfig()
2772
def _show_value(self, name, directory, scope):
2774
for c in self._get_configs(directory, scope):
2777
for (oname, value, section, conf_id, parser) in c._get_options():
2779
# Display only the first value and exit
2781
# FIXME: We need to use get_user_option to take policies
2782
# into account and we need to make sure the option exists
2783
# too (hence the two for loops), this needs a better API
2785
value = c.get_user_option(name)
2786
# Quote the value appropriately
2787
value = parser._quote(value)
2788
self.outf.write('%s\n' % (value,))
2792
raise errors.NoSuchConfigOption(name)
2794
def _show_matching_options(self, name, directory, scope):
2795
name = re.compile(name)
2796
# We want any error in the regexp to be raised *now* so we need to
2797
# avoid the delay introduced by the lazy regexp.
2798
name._compile_and_collapse()
2801
for c in self._get_configs(directory, scope):
2802
for (oname, value, section, conf_id, parser) in c._get_options():
2803
if name.search(oname):
2804
if cur_conf_id != conf_id:
2805
# Explain where the options are defined
2806
self.outf.write('%s:\n' % (conf_id,))
2807
cur_conf_id = conf_id
2809
if (section not in (None, 'DEFAULT')
2810
and cur_section != section):
2811
# Display the section if it's not the default (or only)
2813
self.outf.write(' [%s]\n' % (section,))
2814
cur_section = section
2815
self.outf.write(' %s = %s\n' % (oname, value))
2817
def _set_config_option(self, name, value, directory, scope):
2818
for conf in self._get_configs(directory, scope):
2819
conf.set_user_option(name, value)
2822
raise errors.NoSuchConfig(scope)
2824
def _remove_config_option(self, name, directory, scope):
2826
raise errors.BzrCommandError(
2827
'--remove expects an option to remove.')
2829
for conf in self._get_configs(directory, scope):
2830
for (section_name, section, conf_id) in conf._get_sections():
2831
if scope is not None and conf_id != scope:
2832
# Not the right configuration file
2835
if conf_id != conf.config_id():
2836
conf = self._get_configs(directory, conf_id).next()
2837
# We use the first section in the first config where the
2838
# option is defined to remove it
2839
conf.remove_user_option(name, section_name)
2844
raise errors.NoSuchConfig(scope)
2846
raise errors.NoSuchConfigOption(name)
2850
# We need adapters that can build a Store or a Stack in a test context. Test
2851
# classes, based on TestCaseWithTransport, can use the registry to parametrize
2852
# themselves. The builder will receive a test instance and should return a
2853
# ready-to-use store or stack. Plugins that define new store/stacks can also
2854
# register themselves here to be tested against the tests defined in
2855
# bzrlib.tests.test_config. Note that the builder can be called multiple times
2856
# for the same tests.
2858
# The registered object should be a callable receiving a test instance
2859
# parameter (inheriting from tests.TestCaseWithTransport) and returning a Store
2861
test_store_builder_registry = registry.Registry()
2863
# The registered object should be a callable receiving a test instance
2864
# parameter (inheriting from tests.TestCaseWithTransport) and returning a Stack
2866
test_stack_builder_registry = registry.Registry()