50
49
create_signatures - this option controls whether bzr will always create
51
50
gpg signatures, never create them, or create them if the
52
51
branch is configured to require them.
53
log_format - this option sets the default log format. Possible values are
54
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
56
55
In bazaar.conf you can also define aliases in the ALIASES sections, example
68
from bzrlib.lazy_import import lazy_import
69
lazy_import(globals(), """
71
66
from fnmatch import fnmatch
73
70
from StringIO import StringIO
73
from bzrlib import errors, urlutils
74
from bzrlib.osutils import pathjoin
75
from bzrlib.trace import mutter, warning
84
76
import bzrlib.util.configobj.configobj as configobj
87
from bzrlib.trace import mutter, warning
90
79
CHECK_IF_POSSIBLE=0
102
POLICY_APPENDPATH = 2
106
POLICY_NORECURSE: 'norecurse',
107
POLICY_APPENDPATH: 'appendpath',
112
'norecurse': POLICY_NORECURSE,
113
'appendpath': POLICY_APPENDPATH,
117
STORE_LOCATION = POLICY_NONE
118
STORE_LOCATION_NORECURSE = POLICY_NORECURSE
119
STORE_LOCATION_APPENDPATH = POLICY_APPENDPATH
124
89
class ConfigObj(configobj.ConfigObj):
126
91
def get_bool(self, section, key):
290
250
raise errors.ParseConfigError(e.errors, e.config.filename)
291
251
return self._parser
293
def _get_matching_sections(self):
294
"""Return an ordered list of (section_name, extra_path) pairs.
296
If the section contains inherited configuration, extra_path is
297
a string containing the additional path components.
299
section = self._get_section()
300
if section is not None:
301
return [(section, '')]
305
253
def _get_section(self):
306
254
"""Override this to define the section used by the config."""
309
def _get_option_policy(self, section, option_name):
310
"""Return the policy for the given (section, option_name) pair."""
313
257
def _get_signature_checking(self):
314
258
"""See Config._get_signature_checking."""
315
259
policy = self._get_user_option('check_signatures')
329
273
def _get_user_option(self, option_name):
330
274
"""See Config._get_user_option."""
331
for (section, extra_path) in self._get_matching_sections():
333
value = self._get_parser().get_value(section, option_name)
336
policy = self._get_option_policy(section, option_name)
337
if policy == POLICY_NONE:
339
elif policy == POLICY_NORECURSE:
340
# norecurse items only apply to the exact path
345
elif policy == POLICY_APPENDPATH:
347
value = urlutils.join(value, extra_path)
350
raise AssertionError('Unexpected config policy %r' % policy)
276
return self._get_parser().get_value(self._get_section(),
354
281
def _gpg_signing_command(self):
355
282
"""See Config.gpg_signing_command."""
447
374
location = urlutils.local_path_from_url(location)
448
375
self.location = location
450
def _get_matching_sections(self):
451
"""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
452
384
sections = self._get_parser()
453
385
location_names = self.location.split('/')
454
386
if self.location.endswith('/'):
478
410
# if section is longer, no match.
479
411
if len(section_names) > len(location_names):
481
matches.append((len(section_names), section,
482
'/'.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))
483
423
matches.sort(reverse=True)
485
for (length, section, extra_path) in matches:
486
sections.append((section, extra_path))
487
# should we stop looking for parent configs here?
489
if self._get_parser()[section].as_bool('ignore_parents'):
495
def _get_option_policy(self, section, option_name):
496
"""Return the policy for the given (section, option_name) pair."""
497
# check for the old 'recurse=False' flag
499
recurse = self._get_parser()[section].as_bool('recurse')
503
return POLICY_NORECURSE
505
policy_key = option_name + ':policy'
507
policy_name = self._get_parser()[section][policy_key]
511
return _policy_value[policy_name]
513
def _set_option_policy(self, section, option_name, option_policy):
514
"""Set the policy for the given option name in the given section."""
515
# The old recurse=False option affects all options in the
516
# section. To handle multiple policies in the section, we
517
# need to convert it to a policy_norecurse key.
519
recurse = self._get_parser()[section].as_bool('recurse')
523
symbol_versioning.warn(
524
'The recurse option is deprecated as of 0.14. '
525
'The section "%s" has been converted to use policies.'
528
del self._get_parser()[section]['recurse']
530
for key in self._get_parser()[section].keys():
531
if not key.endswith(':policy'):
532
self._get_parser()[section][key +
533
':policy'] = 'norecurse'
535
policy_key = option_name + ':policy'
536
policy_name = _policy_name[option_policy]
537
if policy_name is not None:
538
self._get_parser()[section][policy_key] = policy_name
540
if policy_key in self._get_parser()[section]:
541
del self._get_parser()[section][policy_key]
543
def set_user_option(self, option, value, store=STORE_LOCATION):
426
def set_user_option(self, option, value):
544
427
"""Save option and its value in the configuration."""
545
assert store in [STORE_LOCATION,
546
STORE_LOCATION_NORECURSE,
547
STORE_LOCATION_APPENDPATH], 'bad storage policy'
548
428
# FIXME: RBC 20051029 This should refresh the parser and also take a
549
429
# file lock on locations.conf.
550
430
conf_dir = os.path.dirname(self._get_filename())
643
def set_user_option(self, name, value, store=STORE_BRANCH,
645
if store == STORE_BRANCH:
521
def set_user_option(self, name, value, local=False):
523
self._get_location_config().set_user_option(name, value)
646
525
self._get_branch_data_config().set_option(value, name)
647
elif store == STORE_GLOBAL:
648
self._get_global_config().set_user_option(name, value)
650
self._get_location_config().set_user_option(name, value, store)
653
if store in (STORE_GLOBAL, STORE_BRANCH):
654
mask_value = self._get_location_config().get_user_option(name)
655
if mask_value is not None:
656
trace.warning('Value "%s" is masked by "%s" from'
657
' locations.conf', value, mask_value)
659
if store == STORE_GLOBAL:
660
branch_config = self._get_branch_data_config()
661
mask_value = branch_config.get_user_option(name)
662
if mask_value is not None:
663
trace.warning('Value "%s" is masked by "%s" from'
664
' branch.conf', value, mask_value)
667
528
def _gpg_signing_command(self):
728
589
base = os.environ.get('BZR_HOME', None)
729
590
if sys.platform == 'win32':
731
base = win32utils.get_appdata_location_unicode()
592
base = os.environ.get('APPDATA', None)
733
594
base = os.environ.get('HOME', None)
735
596
raise errors.BzrError('You must have one of BZR_HOME, APPDATA, or HOME set')
736
return osutils.pathjoin(base, 'bazaar', '2.0')
597
return pathjoin(base, 'bazaar', '2.0')
738
599
# cygwin, linux, and darwin all have a $HOME directory
740
601
base = os.path.expanduser("~")
741
return osutils.pathjoin(base, ".bazaar")
602
return pathjoin(base, ".bazaar")
744
605
def config_filename():
745
606
"""Return per-user configuration ini file filename."""
746
return osutils.pathjoin(config_dir(), 'bazaar.conf')
607
return pathjoin(config_dir(), 'bazaar.conf')
749
610
def branches_config_filename():
750
611
"""Return per-user configuration ini file filename."""
751
return osutils.pathjoin(config_dir(), 'branches.conf')
612
return pathjoin(config_dir(), 'branches.conf')
754
615
def locations_config_filename():
755
616
"""Return per-user configuration ini file filename."""
756
return osutils.pathjoin(config_dir(), 'locations.conf')
617
return pathjoin(config_dir(), 'locations.conf')
759
620
def user_ignore_config_filename():
760
621
"""Return the user default ignore filename"""
761
return osutils.pathjoin(config_dir(), 'ignore')
622
return pathjoin(config_dir(), 'ignore')
764
625
def _auto_user_id():
777
if sys.platform == 'win32':
778
name = win32utils.get_user_name_unicode()
780
raise errors.BzrError("Cannot autodetect user name.\n"
781
"Please, set your name with command like:\n"
782
'bzr whoami "Your Name <name@domain.com>"')
783
host = win32utils.get_host_name_unicode()
785
host = socket.gethostname()
786
return name, (name + '@' + host)
638
# XXX: Any good way to get real user name on win32?