~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/config.py

  • Committer: Patch Queue Manager
  • Date: 2011-09-29 16:16:31 UTC
  • mfrom: (6161.1.6 491196-cmdline-options)
  • Revision ID: pqm@pqm.ubuntu.com-20110929161631-39y752x3cwcljl5w
(vila) Allow configuration options to be overridden from the command line.
 (Vincent Ladeuil)

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 (
2654
2656
        del self.options[name]
2655
2657
 
2656
2658
 
 
2659
class CommandLineSection(MutableSection):
 
2660
    """A section used to carry command line overrides for the config options."""
 
2661
 
 
2662
    def __init__(self, opts=None):
 
2663
        if opts is None:
 
2664
            opts = {}
 
2665
        super(CommandLineSection, self).__init__('cmdline-overrides', opts)
 
2666
 
 
2667
    def _reset(self):
 
2668
        # The dict should be cleared but not replaced so it can be shared.
 
2669
        self.options.clear()
 
2670
 
 
2671
    def _from_cmdline(self, overrides):
 
2672
        # Reset before accepting new definitions
 
2673
        self._reset()
 
2674
        for over in overrides:
 
2675
            try:
 
2676
                name, value = over.split('=', 1)
 
2677
            except ValueError:
 
2678
                raise errors.BzrCommandError(
 
2679
                    gettext("Invalid '%s', should be of the form 'name=value'")
 
2680
                    % (over,))
 
2681
            self.set(name, value)
 
2682
 
 
2683
 
2657
2684
class Store(object):
2658
2685
    """Abstract interface to persistent storage for configuration options."""
2659
2686
 
3275
3302
    def __init__(self):
3276
3303
        # Get a GlobalStore
3277
3304
        gstore = GlobalStore()
3278
 
        super(GlobalStack, self).__init__([gstore.get_sections], gstore)
 
3305
        super(GlobalStack, self).__init__(
 
3306
            [bzrlib.global_state.cmdline_overrides, gstore.get_sections],
 
3307
            gstore)
3279
3308
 
3280
3309
 
3281
3310
class LocationStack(_CompatibleStack):
3289
3318
        matcher = LocationMatcher(lstore, location)
3290
3319
        gstore = GlobalStore()
3291
3320
        super(LocationStack, self).__init__(
3292
 
            [matcher.get_sections, gstore.get_sections], lstore)
 
3321
            [bzrlib.global_state.cmdline_overrides,
 
3322
             matcher.get_sections, gstore.get_sections],
 
3323
            lstore)
3293
3324
 
3294
3325
 
3295
3326
class BranchStack(_CompatibleStack):
3301
3332
        matcher = LocationMatcher(lstore, branch.base)
3302
3333
        gstore = GlobalStore()
3303
3334
        super(BranchStack, self).__init__(
3304
 
            [matcher.get_sections, bstore.get_sections, gstore.get_sections],
 
3335
            [bzrlib.global_state.cmdline_overrides,
 
3336
             matcher.get_sections, bstore.get_sections, gstore.get_sections],
3305
3337
            bstore)
3306
3338
        self.branch = branch
3307
3339