~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/lock.py

  • Committer: Jelmer Vernooij
  • Date: 2011-12-05 14:12:23 UTC
  • mto: This revision was merged to the branch mainline in revision 6348.
  • Revision ID: jelmer@samba.org-20111205141223-8qxae4h37satlzgq
Move more functionality to vf_search.

Show diffs side-by-side

added added

removed removed

Lines of Context:
45
45
    osutils,
46
46
    trace,
47
47
    )
48
 
from bzrlib.hooks import HookPoint, Hooks
49
 
 
 
48
from bzrlib.hooks import Hooks
 
49
from bzrlib.i18n import gettext
50
50
 
51
51
class LockHooks(Hooks):
52
52
 
53
53
    def __init__(self):
54
 
        Hooks.__init__(self)
55
 
        self.create_hook(HookPoint('lock_acquired',
56
 
            "Called with a bzrlib.lock.LockResult when a physical lock is "
57
 
            "acquired.", (1, 8), None))
58
 
        self.create_hook(HookPoint('lock_released',
59
 
            "Called with a bzrlib.lock.LockResult when a physical lock is "
60
 
            "released.", (1, 8), None))
61
 
        self.create_hook(HookPoint('lock_broken',
62
 
            "Called with a bzrlib.lock.LockResult when a physical lock is "
63
 
            "broken.", (1, 15), None))
 
54
        Hooks.__init__(self, "bzrlib.lock", "Lock.hooks")
 
55
        self.add_hook('lock_acquired',
 
56
            "Called with a bzrlib.lock.LockResult when a physical lock is "
 
57
            "acquired.", (1, 8))
 
58
        self.add_hook('lock_released',
 
59
            "Called with a bzrlib.lock.LockResult when a physical lock is "
 
60
            "released.", (1, 8))
 
61
        self.add_hook('lock_broken',
 
62
            "Called with a bzrlib.lock.LockResult when a physical lock is "
 
63
            "broken.", (1, 15))
64
64
 
65
65
 
66
66
class Lock(object):
88
88
                             self.lock_url, self.details)
89
89
 
90
90
 
 
91
class LogicalLockResult(object):
 
92
    """The result of a lock_read/lock_write/lock_tree_write call on lockables.
 
93
 
 
94
    :ivar unlock: A callable which will unlock the lock.
 
95
    """
 
96
 
 
97
    def __init__(self, unlock):
 
98
        self.unlock = unlock
 
99
 
 
100
    def __repr__(self):
 
101
        return "LogicalLockResult(%s)" % (self.unlock)
 
102
 
 
103
 
 
104
 
91
105
def cant_unlock_not_held(locked_object):
92
106
    """An attempt to unlock failed because the object was not locked.
93
107
 
157
171
            self.f.close()
158
172
            self.f = None
159
173
 
160
 
    def __del__(self):
161
 
        if self.f:
162
 
            from warnings import warn
163
 
            warn("lock on %r not released" % self.f)
164
 
            self.unlock()
165
 
 
166
174
    def unlock(self):
167
175
        raise NotImplementedError()
168
176
 
527
535
    locked the same way), and -Drelock is set, then this will trace.note a
528
536
    message about it.
529
537
    """
530
 
    
 
538
 
531
539
    _prev_lock = None
532
540
 
533
541
    def _note_lock(self, lock_type):
536
544
                type_name = 'read'
537
545
            else:
538
546
                type_name = 'write'
539
 
            trace.note('%r was %s locked again', self, type_name)
 
547
            trace.note(gettext('{0!r} was {1} locked again'), self, type_name)
540
548
        self._prev_lock = lock_type
541
549