~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/config.py

  • Committer: Vincent Ladeuil
  • Date: 2011-09-26 15:40:02 UTC
  • mto: This revision was merged to the branch mainline in revision 6178.
  • Revision ID: v.ladeuil+lp@free.fr-20110926154002-exguk3psfpc4b2uw
Allow config options to be overridden from the command line

Show diffs side-by-side

added added

removed removed

Lines of Context:
77
77
import sys
78
78
 
79
79
 
 
80
import bzrlib
80
81
from bzrlib.decorators import needs_write_lock
81
82
from bzrlib.lazy_import import lazy_import
82
83
lazy_import(globals(), """
101
102
    urlutils,
102
103
    win32utils,
103
104
    )
 
105
from bzrlib.i18n import gettext
104
106
from bzrlib.util.configobj import configobj
105
107
""")
106
108
from bzrlib import (
2643
2645
        del self.options[name]
2644
2646
 
2645
2647
 
 
2648
class CommandLineSection(MutableSection):
 
2649
    """A section used to carry command line option overrides."""
 
2650
 
 
2651
    def __init__(self, opts=None):
 
2652
        if opts is None:
 
2653
            opts = {}
 
2654
        super(CommandLineSection, self).__init__('cmdline-overrides', opts)
 
2655
 
 
2656
    def _from_cmdline(self, overrides):
 
2657
        for over in overrides:
 
2658
            try:
 
2659
                name, value = over.split('=', 1)
 
2660
            except ValueError:
 
2661
                raise errors.BzrCommandError(
 
2662
                    gettext("Invalid '%s', should be of the form 'name=value'"))
 
2663
            self.set(name, value)
 
2664
 
 
2665
 
2646
2666
class Store(object):
2647
2667
    """Abstract interface to persistent storage for configuration options."""
2648
2668
 
3264
3284
    def __init__(self):
3265
3285
        # Get a GlobalStore
3266
3286
        gstore = GlobalStore()
3267
 
        super(GlobalStack, self).__init__([gstore.get_sections], gstore)
 
3287
        super(GlobalStack, self).__init__(
 
3288
            [bzrlib.global_state.cmdline_overrides, gstore.get_sections],
 
3289
            gstore)
3268
3290
 
3269
3291
 
3270
3292
class LocationStack(_CompatibleStack):
3278
3300
        matcher = LocationMatcher(lstore, location)
3279
3301
        gstore = GlobalStore()
3280
3302
        super(LocationStack, self).__init__(
3281
 
            [matcher.get_sections, gstore.get_sections], lstore)
 
3303
            [bzrlib.global_state.cmdline_overrides,
 
3304
             matcher.get_sections, gstore.get_sections],
 
3305
            lstore)
3282
3306
 
3283
3307
 
3284
3308
class BranchStack(_CompatibleStack):
3290
3314
        matcher = LocationMatcher(lstore, branch.base)
3291
3315
        gstore = GlobalStore()
3292
3316
        super(BranchStack, self).__init__(
3293
 
            [matcher.get_sections, bstore.get_sections, gstore.get_sections],
 
3317
            [bzrlib.global_state.cmdline_overrides,
 
3318
             matcher.get_sections, bstore.get_sections, gstore.get_sections],
3294
3319
            bstore)
3295
3320
        self.branch = branch
3296
3321