29
29
create_signatures=always|never|when-required(default)
30
30
gpg_signing_command=name-of-program
31
31
log_format=name-of-format
32
validate_signatures_in_log=true|false(default)
33
acceptable_keys=pattern1,pattern2
33
35
in locations.conf, you specify the url of a branch and options for it.
34
36
Wildcards may be used - * and ? as normal in shell completion. Options
40
42
check_signatures= as above
41
43
create_signatures= as above.
44
validate_signatures_in_log=as above
45
acceptable_keys=as above
43
47
explanation of options
44
48
----------------------
45
49
editor - this option sets the pop up editor to use during commits.
46
50
email - this option sets the user id bzr will use when committing.
47
check_signatures - this option controls whether bzr will require good gpg
51
check_signatures - this option will control whether bzr will require good gpg
48
52
signatures, ignore them, or check them if they are
53
present. Currently it is unused except that check_signatures
54
turns on create_signatures.
50
55
create_signatures - this option controls whether bzr will always create
51
gpg signatures, never create them, or create them if the
52
branch is configured to require them.
56
gpg signatures or not on commits. There is an unused
57
option which in future is expected to work if
58
branch settings require signatures.
53
59
log_format - this option sets the default log format. Possible values are
54
60
long, short, line, or a plugin can register new formats.
61
validate_signatures_in_log - show GPG signature validity in log output
62
acceptable_keys - comma separated list of key patterns acceptable for
63
verify-signatures command
56
65
In bazaar.conf you can also define aliases in the ALIASES sections, example
159
168
return self[section][name]
162
# FIXME: Until we can guarantee that each config file is loaded once and and
171
# FIXME: Until we can guarantee that each config file is loaded once and
163
172
# only once for a given bzrlib session, we don't want to re-read the file every
164
173
# time we query for an option so we cache the value (bad ! watch out for tests
165
174
# needing to restore the proper value).This shouldn't be part of 2.4.0 final,
370
379
% (option_name,))
372
381
value = self._expand_options_in_string(value)
382
for hook in OldConfigHooks['get']:
383
hook(self, option_name, value)
375
def get_user_option_as_bool(self, option_name, expand=None):
376
"""Get a generic option as a boolean - no special process, no default.
386
def get_user_option_as_bool(self, option_name, expand=None, default=None):
387
"""Get a generic option as a boolean.
389
:param expand: Allow expanding references to other config values.
390
:param default: Default value if nothing is configured
378
391
:return None if the option doesn't exist or its value can't be
379
392
interpreted as a boolean. Returns True or False otherwise.
381
394
s = self.get_user_option(option_name, expand=expand)
383
396
# The option doesn't exist
385
398
val = ui.bool_from_string(s)
387
400
# The value can't be interpreted as a boolean
424
437
"""See log_format()."""
440
def validate_signatures_in_log(self):
441
"""Show GPG signature validity in log"""
442
result = self._validate_signatures_in_log()
449
def _validate_signatures_in_log(self):
450
"""See validate_signatures_in_log()."""
453
def acceptable_keys(self):
454
"""Comma separated list of key patterns acceptable to
455
verify-signatures command"""
456
result = self._acceptable_keys()
459
def _acceptable_keys(self):
460
"""See acceptable_keys()."""
427
463
def post_commit(self):
428
464
"""An ordered list of python functions to call.
492
528
if policy is None:
493
529
policy = self._get_signature_checking()
494
530
if policy is not None:
531
#this warning should go away once check_signatures is
532
#implemented (if not before)
495
533
trace.warning("Please use create_signatures,"
496
534
" not check_signatures to set signing policy.")
497
if policy == CHECK_ALWAYS:
499
535
elif policy == SIGN_ALWAYS:
546
582
def find_merge_tool(self, name):
547
# We fake a defaults mechanism here by checking if the given name can
583
# We fake a defaults mechanism here by checking if the given name can
548
584
# be found in the known_merge_tools if it's not found in the config.
549
585
# This should be done through the proposed config defaults mechanism
550
586
# when it becomes available in the future.
554
590
return command_line
593
class _ConfigHooks(hooks.Hooks):
594
"""A dict mapping hook names and a list of callables for configs.
598
"""Create the default hooks.
600
These are all empty initially, because by default nothing should get
603
super(_ConfigHooks, self).__init__('bzrlib.config', 'ConfigHooks')
604
self.add_hook('load',
605
'Invoked when a config store is loaded.'
606
' The signature is (store).',
608
self.add_hook('save',
609
'Invoked when a config store is saved.'
610
' The signature is (store).',
612
# The hooks for config options
614
'Invoked when a config option is read.'
615
' The signature is (stack, name, value).',
618
'Invoked when a config option is set.'
619
' The signature is (stack, name, value).',
621
self.add_hook('remove',
622
'Invoked when a config option is removed.'
623
' The signature is (stack, name).',
625
ConfigHooks = _ConfigHooks()
628
class _OldConfigHooks(hooks.Hooks):
629
"""A dict mapping hook names and a list of callables for configs.
633
"""Create the default hooks.
635
These are all empty initially, because by default nothing should get
638
super(_OldConfigHooks, self).__init__('bzrlib.config', 'OldConfigHooks')
639
self.add_hook('load',
640
'Invoked when a config store is loaded.'
641
' The signature is (config).',
643
self.add_hook('save',
644
'Invoked when a config store is saved.'
645
' The signature is (config).',
647
# The hooks for config options
649
'Invoked when a config option is read.'
650
' The signature is (config, name, value).',
653
'Invoked when a config option is set.'
654
' The signature is (config, name, value).',
656
self.add_hook('remove',
657
'Invoked when a config option is removed.'
658
' The signature is (config, name).',
660
OldConfigHooks = _OldConfigHooks()
557
663
class IniBasedConfig(Config):
558
664
"""A configuration policy that draws from ini files."""
619
725
self._parser = ConfigObj(co_input, encoding='utf-8')
620
726
except configobj.ConfigObjError, e:
621
727
raise errors.ParseConfigError(e.errors, e.config.filename)
728
except UnicodeDecodeError:
729
raise errors.ConfigContentError(self.file_name)
622
730
# Make sure self.reload() will use the right file name
623
731
self._parser.filename = self.file_name
732
for hook in OldConfigHooks['load']:
624
734
return self._parser
626
736
def reload(self):
751
863
"""See Config.log_format."""
752
864
return self._get_user_option('log_format')
866
def _validate_signatures_in_log(self):
867
"""See Config.validate_signatures_in_log."""
868
return self._get_user_option('validate_signatures_in_log')
870
def _acceptable_keys(self):
871
"""See Config.acceptable_keys."""
872
return self._get_user_option('acceptable_keys')
754
874
def _post_commit(self):
755
875
"""See Config.post_commit."""
756
876
return self._get_user_option('post_commit')
951
1075
self._get_parser().setdefault(section, {})[option] = value
952
1076
self._write_config_file()
1077
for hook in OldConfigHooks['set']:
1078
hook(self, option, value)
955
1080
def _get_sections(self, name=None):
956
1081
"""See IniBasedConfig._get_sections()."""
1152
1277
# the allowed values of store match the config policies
1153
1278
self._set_option_policy(location, option, store)
1154
1279
self._write_config_file()
1280
for hook in OldConfigHooks['set']:
1281
hook(self, option, value)
1157
1284
class BranchConfig(Config):
1324
1451
"""See Config.log_format."""
1325
1452
return self._get_best_value('_log_format')
1454
def _validate_signatures_in_log(self):
1455
"""See Config.validate_signatures_in_log."""
1456
return self._get_best_value('_validate_signatures_in_log')
1458
def _acceptable_keys(self):
1459
"""See Config.acceptable_keys."""
1460
return self._get_best_value('_acceptable_keys')
1328
1463
def ensure_config_dir_exists(path=None):
1329
1464
"""Make sure a configuration directory exists.
1635
1772
section[option_name] = value
1638
def get_credentials(self, scheme, host, port=None, user=None, path=None,
1775
def get_credentials(self, scheme, host, port=None, user=None, path=None,
1640
1777
"""Returns the matching credentials from authentication.conf file.
2054
2191
section_obj = configobj[section]
2055
2192
except KeyError:
2057
return section_obj.get(name, default)
2194
value = section_obj.get(name, default)
2195
for hook in OldConfigHooks['get']:
2196
hook(self, name, value)
2059
2199
def set_option(self, value, name, section=None):
2060
2200
"""Set the value associated with a named option.
2076
2218
del configobj[option_name]
2078
2220
del configobj[section_name][option_name]
2221
for hook in OldConfigHooks['remove']:
2222
hook(self, option_name)
2079
2223
self._set_configobj(configobj)
2081
2225
def _get_config_file(self):
2083
return StringIO(self._transport.get_bytes(self._filename))
2227
f = StringIO(self._transport.get_bytes(self._filename))
2228
for hook in OldConfigHooks['load']:
2084
2231
except errors.NoSuchFile:
2085
2232
return StringIO()
2234
def _external_url(self):
2235
return urlutils.join(self._transport.external_url(), self._filename)
2087
2237
def _get_configobj(self):
2088
2238
f = self._get_config_file()
2090
return ConfigObj(f, encoding='utf-8')
2241
conf = ConfigObj(f, encoding='utf-8')
2242
except configobj.ConfigObjError, e:
2243
raise errors.ParseConfigError(e.errors, self._external_url())
2244
except UnicodeDecodeError:
2245
raise errors.ConfigContentError(self._external_url())
2094
2250
def _set_configobj(self, configobj):
2095
2251
out_file = StringIO()
2096
2252
configobj.write(out_file)
2097
2253
out_file.seek(0)
2098
2254
self._transport.put_file(self._filename, out_file)
2255
for hook in OldConfigHooks['save']:
2101
2259
class Option(object):
2189
2347
"""Loads the Store from persistent storage."""
2190
2348
raise NotImplementedError(self.load)
2192
def _load_from_string(self, str_or_unicode):
2350
def _load_from_string(self, bytes):
2193
2351
"""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 :)
2353
:param bytes: A string representing the file content.
2201
2355
raise NotImplementedError(self._load_from_string)
2272
2426
content = self.transport.get_bytes(self.file_name)
2273
2427
self._load_from_string(content)
2428
for hook in ConfigHooks['load']:
2275
def _load_from_string(self, str_or_unicode):
2431
def _load_from_string(self, bytes):
2276
2432
"""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 :)
2434
:param bytes: A string representing the file content.
2284
2436
if self.is_loaded():
2285
2437
raise AssertionError('Already loaded: %r' % (self._config_obj,))
2286
co_input = StringIO(str_or_unicode.encode('utf-8'))
2438
co_input = StringIO(bytes)
2288
2440
# The config files are always stored utf8-encoded
2289
2441
self._config_obj = ConfigObj(co_input, encoding='utf-8')
2290
2442
except configobj.ConfigObjError, e:
2291
2443
self._config_obj = None
2292
2444
raise errors.ParseConfigError(e.errors, self.external_url())
2445
except UnicodeDecodeError:
2446
raise errors.ConfigContentError(self.external_url())
2294
2448
def save(self):
2295
2449
if not self.is_loaded():
2604
2762
"""Set a new value for the option."""
2605
2763
section = self._get_mutable_section()
2606
2764
section.set(name, value)
2765
for hook in ConfigHooks['set']:
2766
hook(self, name, value)
2608
2768
def remove(self, name):
2609
2769
"""Remove an existing option."""
2610
2770
section = self._get_mutable_section()
2611
2771
section.remove(name)
2772
for hook in ConfigHooks['remove']:
2613
2775
def __repr__(self):
2614
2776
# Mostly for debugging use
2701
2863
' the configuration file'),
2866
_see_also = ['configuration']
2704
2868
@commands.display_command
2705
2869
def run(self, name=None, all=False, directory=None, scope=None,
2780
2944
raise errors.NoSuchConfigOption(name)
2782
2946
def _show_matching_options(self, name, directory, scope):
2783
name = re.compile(name)
2947
name = lazy_regex.lazy_compile(name)
2784
2948
# We want any error in the regexp to be raised *now* so we need to
2785
# avoid the delay introduced by the lazy regexp.
2949
# avoid the delay introduced by the lazy regexp. But, we still do
2950
# want the nicer errors raised by lazy_regex.
2786
2951
name._compile_and_collapse()
2787
2952
cur_conf_id = None
2788
2953
cur_section = None