49
49
create_signatures - this option controls whether bzr will always create
50
50
gpg signatures, never create them, or create them if the
51
51
branch is configured to require them.
52
log_format - this option sets the default log format. Possible values are
53
long, short, line, or a plugin can register new formats.
52
log_format - This options set the default log format. Options are long,
53
short, line, or a plugin can register new formats
55
55
In bazaar.conf you can also define aliases in the ALIASES sections, example
67
from bzrlib.lazy_import import lazy_import
68
lazy_import(globals(), """
70
66
from fnmatch import fnmatch
72
70
from StringIO import StringIO
73
from bzrlib import errors, urlutils
74
from bzrlib.osutils import pathjoin
75
from bzrlib.trace import mutter, warning
81
76
import bzrlib.util.configobj.configobj as configobj
84
from bzrlib.trace import mutter, warning
87
79
CHECK_IF_POSSIBLE=0
103
POLICY_NORECURSE: 'norecurse',
104
POLICY_APPENDPATH: 'appendpath',
109
'norecurse': POLICY_NORECURSE,
110
'appendpath': POLICY_APPENDPATH,
114
STORE_LOCATION = POLICY_NONE
115
STORE_LOCATION_NORECURSE = POLICY_NORECURSE
116
STORE_LOCATION_APPENDPATH = POLICY_APPENDPATH
121
89
class ConfigObj(configobj.ConfigObj):
123
91
def get_bool(self, section, key):
287
250
raise errors.ParseConfigError(e.errors, e.config.filename)
288
251
return self._parser
290
def _get_matching_sections(self):
291
"""Return an ordered list of (section_name, extra_path) pairs.
293
If the section contains inherited configuration, extra_path is
294
a string containing the additional path components.
296
section = self._get_section()
297
if section is not None:
298
return [(section, '')]
302
253
def _get_section(self):
303
254
"""Override this to define the section used by the config."""
306
def _get_option_policy(self, section, option_name):
307
"""Return the policy for the given (section, option_name) pair."""
310
257
def _get_signature_checking(self):
311
258
"""See Config._get_signature_checking."""
312
259
policy = self._get_user_option('check_signatures')
326
273
def _get_user_option(self, option_name):
327
274
"""See Config._get_user_option."""
328
for (section, extra_path) in self._get_matching_sections():
330
value = self._get_parser().get_value(section, option_name)
333
policy = self._get_option_policy(section, option_name)
334
if policy == POLICY_NONE:
336
elif policy == POLICY_NORECURSE:
337
# norecurse items only apply to the exact path
342
elif policy == POLICY_APPENDPATH:
344
value = urlutils.join(value, extra_path)
347
raise AssertionError('Unexpected config policy %r' % policy)
276
return self._get_parser().get_value(self._get_section(),
351
281
def _gpg_signing_command(self):
352
282
"""See Config.gpg_signing_command."""
444
374
location = urlutils.local_path_from_url(location)
445
375
self.location = location
447
def _get_matching_sections(self):
448
"""Return an ordered list of section names matching this location."""
377
def _get_section(self):
378
"""Get the section we should look in for config items.
380
Returns None if none exists.
381
TODO: perhaps return a NullSection that thunks through to the
449
384
sections = self._get_parser()
450
385
location_names = self.location.split('/')
451
386
if self.location.endswith('/'):
475
410
# if section is longer, no match.
476
411
if len(section_names) > len(location_names):
478
matches.append((len(section_names), section,
479
'/'.join(location_names[len(section_names):])))
413
# if path is longer, and recurse is not true, no match
414
if len(section_names) < len(location_names):
416
if not self._get_parser()[section].as_bool('recurse'):
420
matches.append((len(section_names), section))
480
423
matches.sort(reverse=True)
482
for (length, section, extra_path) in matches:
483
sections.append((section, extra_path))
484
# should we stop looking for parent configs here?
486
if self._get_parser()[section].as_bool('ignore_parents'):
492
def _get_option_policy(self, section, option_name):
493
"""Return the policy for the given (section, option_name) pair."""
494
# check for the old 'recurse=False' flag
496
recurse = self._get_parser()[section].as_bool('recurse')
500
return POLICY_NORECURSE
502
policy_key = option_name + ':policy'
504
policy_name = self._get_parser()[section][policy_key]
508
return _policy_value[policy_name]
510
def _set_option_policy(self, section, option_name, option_policy):
511
"""Set the policy for the given option name in the given section."""
512
# The old recurse=False option affects all options in the
513
# section. To handle multiple policies in the section, we
514
# need to convert it to a policy_norecurse key.
516
recurse = self._get_parser()[section].as_bool('recurse')
520
symbol_versioning.warn(
521
'The recurse option is deprecated as of 0.14. '
522
'The section "%s" has been converted to use policies.'
525
del self._get_parser()[section]['recurse']
527
for key in self._get_parser()[section].keys():
528
if not key.endswith(':policy'):
529
self._get_parser()[section][key +
530
':policy'] = 'norecurse'
532
policy_key = option_name + ':policy'
533
policy_name = _policy_name[option_policy]
534
if policy_name is not None:
535
self._get_parser()[section][policy_key] = policy_name
537
if policy_key in self._get_parser()[section]:
538
del self._get_parser()[section][policy_key]
540
def set_user_option(self, option, value, store=STORE_LOCATION):
426
def set_user_option(self, option, value):
541
427
"""Save option and its value in the configuration."""
542
assert store in [STORE_LOCATION,
543
STORE_LOCATION_NORECURSE,
544
STORE_LOCATION_APPENDPATH], 'bad storage policy'
545
428
# FIXME: RBC 20051029 This should refresh the parser and also take a
546
429
# file lock on locations.conf.
547
430
conf_dir = os.path.dirname(self._get_filename())
640
def set_user_option(self, name, value, store=STORE_BRANCH):
641
if store == STORE_BRANCH:
521
def set_user_option(self, name, value, local=False):
523
self._get_location_config().set_user_option(name, value)
642
525
self._get_branch_data_config().set_option(value, name)
643
elif store == STORE_GLOBAL:
644
self._get_global_config().set_user_option(name, value)
646
self._get_location_config().set_user_option(name, value, store)
648
528
def _gpg_signing_command(self):
649
529
"""See Config.gpg_signing_command."""
714
594
base = os.environ.get('HOME', None)
716
596
raise errors.BzrError('You must have one of BZR_HOME, APPDATA, or HOME set')
717
return osutils.pathjoin(base, 'bazaar', '2.0')
597
return pathjoin(base, 'bazaar', '2.0')
719
599
# cygwin, linux, and darwin all have a $HOME directory
721
601
base = os.path.expanduser("~")
722
return osutils.pathjoin(base, ".bazaar")
602
return pathjoin(base, ".bazaar")
725
605
def config_filename():
726
606
"""Return per-user configuration ini file filename."""
727
return osutils.pathjoin(config_dir(), 'bazaar.conf')
607
return pathjoin(config_dir(), 'bazaar.conf')
730
610
def branches_config_filename():
731
611
"""Return per-user configuration ini file filename."""
732
return osutils.pathjoin(config_dir(), 'branches.conf')
612
return pathjoin(config_dir(), 'branches.conf')
735
615
def locations_config_filename():
736
616
"""Return per-user configuration ini file filename."""
737
return osutils.pathjoin(config_dir(), 'locations.conf')
617
return pathjoin(config_dir(), 'locations.conf')
740
620
def user_ignore_config_filename():
741
621
"""Return the user default ignore filename"""
742
return osutils.pathjoin(config_dir(), 'ignore')
622
return pathjoin(config_dir(), 'ignore')
745
625
def _auto_user_id():