~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/lock.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2011-06-30 18:28:17 UTC
  • mfrom: (5967.10.2 test-cat)
  • Revision ID: pqm@pqm.ubuntu.com-20110630182817-83a5q9r9rxfkdn8r
(mbp) don't use subprocesses for testing cat (Martin Pool)

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
 
17
 
17
18
"""Locking using OS file locks or file existence.
18
19
 
19
20
Note: This method of locking is generally deprecated in favour of LockDir, but
33
34
unlock() method.
34
35
"""
35
36
 
36
 
from __future__ import absolute_import
37
 
 
38
 
import contextlib
39
37
import errno
40
38
import os
41
39
import sys
48
46
    trace,
49
47
    )
50
48
from bzrlib.hooks import Hooks
51
 
from bzrlib.i18n import gettext
 
49
 
52
50
 
53
51
class LockHooks(Hooks):
54
52
 
537
535
    locked the same way), and -Drelock is set, then this will trace.note a
538
536
    message about it.
539
537
    """
540
 
 
 
538
    
541
539
    _prev_lock = None
542
540
 
543
541
    def _note_lock(self, lock_type):
546
544
                type_name = 'read'
547
545
            else:
548
546
                type_name = 'write'
549
 
            trace.note(gettext('{0!r} was {1} locked again'), self, type_name)
 
547
            trace.note('%r was %s locked again', self, type_name)
550
548
        self._prev_lock = lock_type
551
549
 
552
 
@contextlib.contextmanager
553
 
def write_locked(lockable):
554
 
    lockable.lock_write()
555
 
    try:
556
 
        yield lockable
557
 
    finally:
558
 
        lockable.unlock()