~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/config.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2011-05-31 18:19:32 UTC
  • mfrom: (5743.6.32 config-locks)
  • Revision ID: pqm@pqm.ubuntu.com-20110531181932-l8lk4840z7dty5sa
(vila) Implement config locking. (Vincent Ladeuil)

Show diffs side-by-side

added added

removed removed

Lines of Context:
199
199
        return diff.DiffFromTool.from_string(cmd, old_tree, new_tree,
200
200
                                             sys.stdout)
201
201
 
202
 
 
203
202
    def get_mail_client(self):
204
203
        """Get a mail client to use"""
205
204
        selected_client = self.get_user_option('mail_client')
2334
2333
 
2335
2334
    @needs_write_lock
2336
2335
    def save(self):
 
2336
        # We need to be able to override the undecorated implementation
 
2337
        self.save_without_locking()
 
2338
 
 
2339
    def save_without_locking(self):
2337
2340
        super(LockableIniFileStore, self).save()
2338
2341
 
2339
2342
 
2361
2364
        super(LocationStore, self).__init__(t, 'locations.conf')
2362
2365
 
2363
2366
 
2364
 
class BranchStore(IniFileStore):
 
2367
# FIXME: We should rely on the branch itself to be locked (possibly checking
 
2368
# that even) but we shouldn't lock ourselves. This may make `bzr config` is
 
2369
# a bit trickier though but I punt for now -- vila 20110512
 
2370
class BranchStore(LockableIniFileStore):
2365
2371
 
2366
2372
    def __init__(self, branch):
2367
2373
        super(BranchStore, self).__init__(branch.control_transport,
2540
2546
        return "<config.%s(%s)>" % (self.__class__.__name__, id(self))
2541
2547
 
2542
2548
 
2543
 
class GlobalStack(Stack):
 
2549
class _CompatibleStack(Stack):
 
2550
    """Place holder for compatibility with previous design.
 
2551
 
 
2552
    This is intended to ease the transition from the Config-based design to the
 
2553
    Stack-based design and should not be used nor relied upon by plugins.
 
2554
 
 
2555
    One assumption made here is that the daughter classes will all use Stores
 
2556
    derived from LockableIniFileStore).
 
2557
 
 
2558
    It implements set() by re-loading the store before applying the
 
2559
    modification and saving it.
 
2560
 
 
2561
    The long term plan being to implement a single write by store to save
 
2562
    all modifications, this class should not be used in the interim.
 
2563
    """
 
2564
 
 
2565
    def set(self, name, value):
 
2566
        # Force a reload (assuming we use a LockableIniFileStore)
 
2567
        self.store._config_obj = None
 
2568
        super(_CompatibleStack, self).set(name, value)
 
2569
        # Force a write to persistent storage
 
2570
        self.store.save()
 
2571
 
 
2572
 
 
2573
class GlobalStack(_CompatibleStack):
2544
2574
 
2545
2575
    def __init__(self):
2546
2576
        # Get a GlobalStore
2548
2578
        super(GlobalStack, self).__init__([gstore.get_sections], gstore)
2549
2579
 
2550
2580
 
2551
 
class LocationStack(Stack):
 
2581
class LocationStack(_CompatibleStack):
2552
2582
 
2553
2583
    def __init__(self, location):
2554
2584
        lstore = LocationStore()
2557
2587
        super(LocationStack, self).__init__(
2558
2588
            [matcher.get_sections, gstore.get_sections], lstore)
2559
2589
 
2560
 
 
2561
 
class BranchStack(Stack):
 
2590
# FIXME: See BranchStore, same remarks -- vila 20110512
 
2591
class BranchStack(_CompatibleStack):
2562
2592
 
2563
2593
    def __init__(self, branch):
2564
2594
        bstore = BranchStore(branch)
2733
2763
            raise errors.NoSuchConfig(scope)
2734
2764
        if not removed:
2735
2765
            raise errors.NoSuchConfigOption(name)
 
2766
 
 
2767
 
 
2768
# Test registries
 
2769
#
 
2770
# We need adapters that can build a Store or a Stack in a test context. Test
 
2771
# classes, based on TestCaseWithTransport, can use the registry to parametrize
 
2772
# themselves. The builder will receive a test instance and should return a
 
2773
# ready-to-use store or stack.  Plugins that define new store/stacks can also
 
2774
# register themselves here to be tested against the tests defined in
 
2775
# bzrlib.tests.test_config.
 
2776
 
 
2777
# The registered object should be a callable receiving a test instance
 
2778
# parameter (inheriting from tests.TestCaseWithTransport) and returning a Store
 
2779
# object.
 
2780
test_store_builder_registry = registry.Registry()
 
2781
 
 
2782
# Thre registered object should be a callable receiving a test instance
 
2783
# parameter (inheriting from tests.TestCaseWithTransport) and returning a Stack
 
2784
# object.
 
2785
test_stack_builder_registry = registry.Registry()