~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/config.py

  • Committer: John Arbash Meinel
  • Date: 2006-08-14 16:16:53 UTC
  • mto: (1946.2.6 reduce-knit-churn)
  • mto: This revision was merged to the branch mainline in revision 1919.
  • Revision ID: john@arbash-meinel.com-20060814161653-54cdcdadcd4e9003
Remove bogus entry from BRANCH.TODO

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005 Canonical Ltd
 
1
# Copyright (C) 2005 by Canonical Ltd
2
2
#   Authors: Robert Collins <robert.collins@canonical.com>
3
3
#
4
4
# This program is free software; you can redistribute it and/or modify
61
61
up=pull
62
62
"""
63
63
 
64
 
import os
65
 
import sys
66
64
 
67
 
from bzrlib.lazy_import import lazy_import
68
 
lazy_import(globals(), """
69
65
import errno
70
66
from fnmatch import fnmatch
 
67
import os
71
68
import re
 
69
import sys
72
70
from StringIO import StringIO
73
71
 
74
72
import bzrlib
75
 
from bzrlib import (
76
 
    errors,
77
 
    osutils,
78
 
    urlutils,
79
 
    )
 
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
81
 
""")
82
 
 
83
 
from bzrlib.trace import mutter, warning
84
77
 
85
78
 
86
79
CHECK_IF_POSSIBLE=0
262
255
            raise errors.ParseConfigError(e.errors, e.config.filename)
263
256
        return self._parser
264
257
 
265
 
    def _get_matching_sections(self):
266
 
        """Return an ordered list of (section_name, extra_path) pairs.
267
 
 
268
 
        If the section contains inherited configuration, extra_path is
269
 
        a string containing the additional path components.
270
 
        """
271
 
        section = self._get_section()
272
 
        if section is not None:
273
 
            return [(section, '')]
274
 
        else:
275
 
            return []
276
 
 
277
258
    def _get_section(self):
278
259
        """Override this to define the section used by the config."""
279
260
        return "DEFAULT"
296
277
 
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():
300
 
            try:
301
 
                return self._get_parser().get_value(section, option_name)
302
 
            except KeyError:
303
 
                pass
304
 
        else:
305
 
            return None
 
280
        try:
 
281
            return self._get_parser().get_value(self._get_section(),
 
282
                                                option_name)
 
283
        except KeyError:
 
284
            pass
306
285
 
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
402
381
 
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.
 
384
 
 
385
        Returns None if none exists. 
 
386
        TODO: perhaps return a NullSection that thunks through to the 
 
387
              global config.
 
388
        """
405
389
        sections = self._get_parser()
406
390
        location_names = self.location.split('/')
407
391
        if self.location.endswith('/'):
438
422
                        continue
439
423
                except KeyError:
440
424
                    pass
441
 
            matches.append((len(section_names), section,
442
 
                            '/'.join(location_names[len(section_names):])))
 
425
            matches.append((len(section_names), section))
 
426
        if not len(matches):
 
427
            return None
443
428
        matches.sort(reverse=True)
444
 
        sections = []
445
 
        for (length, section, extra_path) in matches:
446
 
            sections.append((section, extra_path))
447
 
            # should we stop looking for parent configs here?
448
 
            try:
449
 
                if self._get_parser()[section].as_bool('ignore_parents'):
450
 
                    break
451
 
            except KeyError:
452
 
                pass
453
 
        return sections
 
429
        return matches[0][1]
454
430
 
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)
624
600
        if base is 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')
627
603
    else:
628
604
        # cygwin, linux, and darwin all have a $HOME directory
629
605
        if base is None:
630
606
            base = os.path.expanduser("~")
631
 
        return osutils.pathjoin(base, ".bazaar")
 
607
        return pathjoin(base, ".bazaar")
632
608
 
633
609
 
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')
637
613
 
638
614
 
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')
642
618
 
643
619
 
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')
647
623
 
648
624
 
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')
652
628
 
653
629
 
654
630
def _auto_user_id():
722
698
    """
723
699
    m = re.search(r'[\w+.-]+@[\w+.-]+', e)
724
700
    if not m:
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)
727
704
 
728
705