/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/config.py

  • Committer: Jelmer Vernooij
  • Date: 2011-10-03 14:50:03 UTC
  • mfrom: (6183 +trunk)
  • mto: This revision was merged to the branch mainline in revision 6184.
  • Revision ID: jelmer@samba.org-20111003145003-6x5mqsdb2csqoxz7
Merge bzr.dev.

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 (
2361
2363
                raise AssertionError(
2362
2364
                    'Only empty lists are supported as default values')
2363
2365
            self.default = u','
2364
 
        elif isinstance(default, (str, unicode, bool, int)):
 
2366
        elif isinstance(default, (str, unicode, bool, int, float)):
2365
2367
            # Rely on python to convert strings, booleans and integers
2366
2368
            self.default = u'%s' % (default,)
2367
2369
        else:
2426
2428
    return int(unicode_str)
2427
2429
 
2428
2430
 
 
2431
def float_from_store(unicode_str):
 
2432
    return float(unicode_str)
 
2433
 
 
2434
 
 
2435
 
2429
2436
# Use a an empty dict to initialize an empty configobj avoiding all
2430
2437
# parsing and encoding checks
2431
2438
_list_converter_config = configobj.ConfigObj(
2596
2603
uncommitted changes before pushing.
2597
2604
'''))
2598
2605
 
 
2606
option_registry.register(
 
2607
    Option('serve.client_timeout',
 
2608
           default=300.0, from_unicode=float_from_store,
 
2609
           help="If we wait for a new request from a client for more than"
 
2610
                " X seconds, consider the client idle, and hangup."))
 
2611
 
2599
2612
 
2600
2613
class Section(object):
2601
2614
    """A section defines a dict of option name => value.
2643
2656
        del self.options[name]
2644
2657
 
2645
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
 
2646
2684
class Store(object):
2647
2685
    """Abstract interface to persistent storage for configuration options."""
2648
2686
 
3264
3302
    def __init__(self):
3265
3303
        # Get a GlobalStore
3266
3304
        gstore = GlobalStore()
3267
 
        super(GlobalStack, self).__init__([gstore.get_sections], gstore)
 
3305
        super(GlobalStack, self).__init__(
 
3306
            [bzrlib.global_state.cmdline_overrides, gstore.get_sections],
 
3307
            gstore)
3268
3308
 
3269
3309
 
3270
3310
class LocationStack(_CompatibleStack):
3278
3318
        matcher = LocationMatcher(lstore, location)
3279
3319
        gstore = GlobalStore()
3280
3320
        super(LocationStack, self).__init__(
3281
 
            [matcher.get_sections, gstore.get_sections], lstore)
 
3321
            [bzrlib.global_state.cmdline_overrides,
 
3322
             matcher.get_sections, gstore.get_sections],
 
3323
            lstore)
3282
3324
 
3283
3325
 
3284
3326
class BranchStack(_CompatibleStack):
3290
3332
        matcher = LocationMatcher(lstore, branch.base)
3291
3333
        gstore = GlobalStore()
3292
3334
        super(BranchStack, self).__init__(
3293
 
            [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],
3294
3337
            bstore)
3295
3338
        self.branch = branch
3296
3339