~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/lock.py

  • Committer: John Arbash Meinel
  • Date: 2008-10-30 00:55:00 UTC
  • mto: (3815.2.5 prepare-1.9)
  • mto: This revision was merged to the branch mainline in revision 3811.
  • Revision ID: john@arbash-meinel.com-20081030005500-r5cej1cxflqhs3io
Switch so that we are using a simple timestamp as the first action.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006, 2007 Canonical Ltd
 
1
# Copyright (C) 2005, 2006, 2007, 2008 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
42
42
    osutils,
43
43
    trace,
44
44
    )
 
45
from bzrlib.hooks import Hooks
 
46
 
 
47
 
 
48
class LockHooks(Hooks):
 
49
 
 
50
    def __init__(self):
 
51
        Hooks.__init__(self)
 
52
 
 
53
        # added in 1.8; called with a LockResult when a physical lock is
 
54
        # acquired
 
55
        self['lock_acquired'] = []
 
56
 
 
57
        # added in 1.8; called with a LockResult when a physical lock is
 
58
        # acquired
 
59
        self['lock_released'] = []
 
60
 
 
61
 
 
62
class Lock(object):
 
63
    """Base class for locks.
 
64
 
 
65
    :cvar hooks: Hook dictionary for operations on locks.
 
66
    """
 
67
 
 
68
    hooks = LockHooks()
 
69
 
 
70
 
 
71
class LockResult(object):
 
72
    """Result of an operation on a lock; passed to a hook"""
 
73
 
 
74
    def __init__(self, lock_url, details=None):
 
75
        """Create a lock result for lock with optional details about the lock."""
 
76
        self.lock_url = lock_url
 
77
        self.details = details
 
78
 
 
79
    def __eq__(self, other):
 
80
        return self.lock_url == other.lock_url and self.details == other.details
 
81
 
 
82
 
 
83
try:
 
84
    import fcntl
 
85
    have_fcntl = True
 
86
except ImportError:
 
87
    have_fcntl = False
 
88
 
 
89
have_pywin32 = False
 
90
have_ctypes_win32 = False
 
91
if sys.platform == 'win32':
 
92
    import msvcrt
 
93
    try:
 
94
        import win32con, win32file, pywintypes, winerror
 
95
        have_pywin32 = True
 
96
    except ImportError:
 
97
        pass
 
98
 
 
99
    try:
 
100
        import ctypes
 
101
        have_ctypes_win32 = True
 
102
    except ImportError:
 
103
        pass
45
104
 
46
105
 
47
106
class _OSLock(object):
83
142
        raise NotImplementedError()
84
143
 
85
144
 
86
 
try:
87
 
    import fcntl
88
 
    have_fcntl = True
89
 
except ImportError:
90
 
    have_fcntl = False
91
 
try:
92
 
    import win32con, win32file, pywintypes, winerror, msvcrt
93
 
    have_pywin32 = True
94
 
except ImportError:
95
 
    have_pywin32 = False
96
 
try:
97
 
    import ctypes, msvcrt
98
 
    have_ctypes = True
99
 
except ImportError:
100
 
    have_ctypes = False
101
 
 
102
 
 
103
145
_lock_classes = []
104
146
 
105
147
 
332
374
    _lock_classes.append(('pywin32', _w32c_WriteLock, _w32c_ReadLock))
333
375
 
334
376
 
335
 
if have_ctypes and sys.platform == 'win32':
 
377
if have_ctypes_win32:
336
378
    # These constants were copied from the win32con.py module.
337
379
    LOCKFILE_FAIL_IMMEDIATELY = 1
338
380
    LOCKFILE_EXCLUSIVE_LOCK = 2