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
80
76
import bzrlib.util.configobj.configobj as configobj
83
from bzrlib.trace import mutter, warning
86
79
CHECK_IF_POSSIBLE=0
262
255
raise errors.ParseConfigError(e.errors, e.config.filename)
263
256
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, '')]
277
258
def _get_section(self):
278
259
"""Override this to define the section used by the config."""
297
278
def _get_user_option(self, option_name):
298
279
"""See Config._get_user_option."""
299
for (section, extra_path) in self._get_matching_sections():
301
return self._get_parser().get_value(section, option_name)
281
return self._get_parser().get_value(self._get_section(),
307
286
def _gpg_signing_command(self):
308
287
"""See Config.gpg_signing_command."""
400
379
location = urlutils.local_path_from_url(location)
401
380
self.location = location
403
def _get_matching_sections(self):
404
"""Return an ordered list of section names matching this 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
405
389
sections = self._get_parser()
406
390
location_names = self.location.split('/')
407
391
if self.location.endswith('/'):
441
matches.append((len(section_names), section,
442
'/'.join(location_names[len(section_names):])))
425
matches.append((len(section_names), section))
443
428
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'):
455
431
def set_user_option(self, option, value):
456
432
"""Save option and its value in the configuration."""
623
599
base = os.environ.get('HOME', None)
625
601
raise errors.BzrError('You must have one of BZR_HOME, APPDATA, or HOME set')
626
return osutils.pathjoin(base, 'bazaar', '2.0')
602
return pathjoin(base, 'bazaar', '2.0')
628
604
# cygwin, linux, and darwin all have a $HOME directory
630
606
base = os.path.expanduser("~")
631
return osutils.pathjoin(base, ".bazaar")
607
return pathjoin(base, ".bazaar")
634
610
def config_filename():
635
611
"""Return per-user configuration ini file filename."""
636
return osutils.pathjoin(config_dir(), 'bazaar.conf')
612
return pathjoin(config_dir(), 'bazaar.conf')
639
615
def branches_config_filename():
640
616
"""Return per-user configuration ini file filename."""
641
return osutils.pathjoin(config_dir(), 'branches.conf')
617
return pathjoin(config_dir(), 'branches.conf')
644
620
def locations_config_filename():
645
621
"""Return per-user configuration ini file filename."""
646
return osutils.pathjoin(config_dir(), 'locations.conf')
622
return pathjoin(config_dir(), 'locations.conf')
649
625
def user_ignore_config_filename():
650
626
"""Return the user default ignore filename"""
651
return osutils.pathjoin(config_dir(), 'ignore')
627
return pathjoin(config_dir(), 'ignore')
654
630
def _auto_user_id():
723
699
m = re.search(r'[\w+.-]+@[\w+.-]+', e)
725
raise errors.NoEmailInUsername(e)
701
raise errors.BzrError("%r doesn't seem to contain "
702
"a reasonable email address" % e)
726
703
return m.group(0)