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
import bzrlib.errors as errors
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."""
440
367
' to ~/.bazaar/locations.conf')
441
368
name_generator = branches_config_filename
442
369
super(LocationConfig, self).__init__(name_generator)
443
# local file locations are looked up by local path, rather than
444
# by file url. This is because the config file is a user
445
# file, and we would rather not expose the user to file urls.
446
if location.startswith('file://'):
447
location = urlutils.local_path_from_url(location)
448
370
self.location = location
450
def _get_matching_sections(self):
451
"""Return an ordered list of section names matching this location."""
372
def _get_section(self):
373
"""Get the section we should look in for config items.
375
Returns None if none exists.
376
TODO: perhaps return a NullSection that thunks through to the
452
379
sections = self._get_parser()
453
380
location_names = self.location.split('/')
454
381
if self.location.endswith('/'):
455
382
del location_names[-1]
457
384
for section in sections:
458
# location is a local path if possible, so we need
459
# to convert 'file://' urls to local paths if necessary.
460
# This also avoids having file:///path be a more exact
461
# match than '/path'.
462
if section.startswith('file://'):
463
section_path = urlutils.local_path_from_url(section)
465
section_path = section
466
section_names = section_path.split('/')
385
section_names = section.split('/')
467
386
if section.endswith('/'):
468
387
del section_names[-1]
469
388
names = zip(location_names, section_names)
478
397
# if section is longer, no match.
479
398
if len(section_names) > len(location_names):
481
matches.append((len(section_names), section,
482
'/'.join(location_names[len(section_names):])))
400
# if path is longer, and recurse is not true, no match
401
if len(section_names) < len(location_names):
403
if not self._get_parser()[section].as_bool('recurse'):
407
matches.append((len(section_names), section))
483
410
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):
413
def set_user_option(self, option, value):
544
414
"""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
415
# FIXME: RBC 20051029 This should refresh the parser and also take a
549
416
# file lock on locations.conf.
550
417
conf_dir = os.path.dirname(self._get_filename())
643
def set_user_option(self, name, value, store=STORE_BRANCH,
645
if store == STORE_BRANCH:
508
def set_user_option(self, name, value, local=False):
510
self._get_location_config().set_user_option(name, value)
646
512
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
515
def _gpg_signing_command(self):
728
576
base = os.environ.get('BZR_HOME', None)
729
577
if sys.platform == 'win32':
731
base = win32utils.get_appdata_location_unicode()
579
base = os.environ.get('APPDATA', None)
733
581
base = os.environ.get('HOME', None)
735
583
raise errors.BzrError('You must have one of BZR_HOME, APPDATA, or HOME set')
736
return osutils.pathjoin(base, 'bazaar', '2.0')
584
return pathjoin(base, 'bazaar', '2.0')
738
586
# cygwin, linux, and darwin all have a $HOME directory
740
588
base = os.path.expanduser("~")
741
return osutils.pathjoin(base, ".bazaar")
589
return pathjoin(base, ".bazaar")
744
592
def config_filename():
745
593
"""Return per-user configuration ini file filename."""
746
return osutils.pathjoin(config_dir(), 'bazaar.conf')
594
return pathjoin(config_dir(), 'bazaar.conf')
749
597
def branches_config_filename():
750
598
"""Return per-user configuration ini file filename."""
751
return osutils.pathjoin(config_dir(), 'branches.conf')
599
return pathjoin(config_dir(), 'branches.conf')
754
602
def locations_config_filename():
755
603
"""Return per-user configuration ini file filename."""
756
return osutils.pathjoin(config_dir(), 'locations.conf')
759
def user_ignore_config_filename():
760
"""Return the user default ignore filename"""
761
return osutils.pathjoin(config_dir(), 'ignore')
604
return pathjoin(config_dir(), 'locations.conf')
764
607
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)
620
# XXX: Any good way to get real user name on win32?