67
from bzrlib.lazy_import import lazy_import
68
lazy_import(globals(), """
66
70
from fnmatch import fnmatch
70
72
from StringIO import StringIO
73
from bzrlib import errors, urlutils
74
from bzrlib.osutils import pathjoin
80
import bzrlib.util.configobj.configobj as configobj
75
83
from bzrlib.trace import mutter, warning
76
import bzrlib.util.configobj.configobj as configobj
79
86
CHECK_IF_POSSIBLE=0
255
262
raise errors.ParseConfigError(e.errors, e.config.filename)
256
263
return self._parser
265
def _get_matching_sections(self):
266
"""Return an ordered list of (section_name, extra_path) pairs.
268
If the section contains inherited configuration, extra_path is
269
a string containing the additional path components.
271
section = self._get_section()
272
if section is not None:
273
return [(section, '')]
258
277
def _get_section(self):
259
278
"""Override this to define the section used by the config."""
278
297
def _get_user_option(self, option_name):
279
298
"""See Config._get_user_option."""
281
return self._get_parser().get_value(self._get_section(),
299
for (section, extra_path) in self._get_matching_sections():
301
return self._get_parser().get_value(section, option_name)
286
307
def _gpg_signing_command(self):
287
308
"""See Config.gpg_signing_command."""
379
400
location = urlutils.local_path_from_url(location)
380
401
self.location = location
382
def _get_section(self):
383
"""Get the section we should look in for config items.
385
Returns None if none exists.
386
TODO: perhaps return a NullSection that thunks through to the
403
def _get_matching_sections(self):
404
"""Return an ordered list of section names matching this location."""
389
405
sections = self._get_parser()
390
406
location_names = self.location.split('/')
391
407
if self.location.endswith('/'):
425
matches.append((len(section_names), section))
441
matches.append((len(section_names), section,
442
'/'.join(location_names[len(section_names):])))
428
443
matches.sort(reverse=True)
445
for (length, section, extra_path) in matches:
446
sections.append((section, extra_path))
447
# should we stop looking for parent configs here?
449
if self._get_parser()[section].as_bool('ignore_parents'):
431
455
def set_user_option(self, option, value):
432
456
"""Save option and its value in the configuration."""
599
623
base = os.environ.get('HOME', None)
601
625
raise errors.BzrError('You must have one of BZR_HOME, APPDATA, or HOME set')
602
return pathjoin(base, 'bazaar', '2.0')
626
return osutils.pathjoin(base, 'bazaar', '2.0')
604
628
# cygwin, linux, and darwin all have a $HOME directory
606
630
base = os.path.expanduser("~")
607
return pathjoin(base, ".bazaar")
631
return osutils.pathjoin(base, ".bazaar")
610
634
def config_filename():
611
635
"""Return per-user configuration ini file filename."""
612
return pathjoin(config_dir(), 'bazaar.conf')
636
return osutils.pathjoin(config_dir(), 'bazaar.conf')
615
639
def branches_config_filename():
616
640
"""Return per-user configuration ini file filename."""
617
return pathjoin(config_dir(), 'branches.conf')
641
return osutils.pathjoin(config_dir(), 'branches.conf')
620
644
def locations_config_filename():
621
645
"""Return per-user configuration ini file filename."""
622
return pathjoin(config_dir(), 'locations.conf')
646
return osutils.pathjoin(config_dir(), 'locations.conf')
625
649
def user_ignore_config_filename():
626
650
"""Return the user default ignore filename"""
627
return pathjoin(config_dir(), 'ignore')
651
return osutils.pathjoin(config_dir(), 'ignore')
630
654
def _auto_user_id():
699
723
m = re.search(r'[\w+.-]+@[\w+.-]+', e)
701
raise errors.BzrError("%r doesn't seem to contain "
702
"a reasonable email address" % e)
725
raise errors.NoEmailInUsername(e)
703
726
return m.group(0)