~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/lockable_files.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2008-06-09 07:45:19 UTC
  • mfrom: (3484.2.1 trunk)
  • Revision ID: pqm@pqm.ubuntu.com-20080609074519-afx3xh7bd8wqzjy0
(vila) Trivial drive-by cleanups

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
from cStringIO import StringIO
18
 
 
19
 
from bzrlib.lazy_import import lazy_import
20
 
lazy_import(globals(), """
21
18
import codecs
22
 
import warnings
23
 
 
24
 
from bzrlib import (
25
 
    errors,
26
 
    osutils,
27
 
    transactions,
28
 
    urlutils,
29
 
    )
30
 
""")
31
 
 
32
 
from bzrlib.decorators import (
33
 
    needs_read_lock,
34
 
    needs_write_lock,
35
 
    )
 
19
#import traceback
 
20
from warnings import warn
 
21
 
 
22
import bzrlib
 
23
from bzrlib.decorators import (needs_read_lock,
 
24
        needs_write_lock)
 
25
import bzrlib.errors as errors
 
26
from bzrlib.errors import BzrError
 
27
from bzrlib.osutils import file_iterator, safe_unicode
36
28
from bzrlib.symbol_versioning import (
37
29
    deprecated_in,
38
30
    deprecated_method,
39
31
    )
 
32
from bzrlib.trace import mutter, note
 
33
import bzrlib.transactions as transactions
 
34
import bzrlib.urlutils as urlutils
40
35
 
41
36
 
42
37
# XXX: The tracking here of lock counts and whether the lock is held is
113
108
        if self.is_locked():
114
109
            # do not automatically unlock; there should have been a
115
110
            # try/finally to unlock this.
116
 
            warnings.warn("%r was gc'd while locked" % self)
 
111
            warn("%r was gc'd while locked" % self)
117
112
 
118
113
    def break_lock(self):
119
114
        """Break the lock of this lockable files group if it is held.
127
122
            file_or_path = '/'.join(file_or_path)
128
123
        if file_or_path == '':
129
124
            return u''
130
 
        return urlutils.escape(osutils.safe_unicode(file_or_path))
 
125
        return urlutils.escape(safe_unicode(file_or_path))
131
126
 
132
127
    def _find_modes(self):
133
128
        """Determine the appropriate modes for files and directories.
246
241
        some other way, and need to synchronise this object's state with that
247
242
        fact.
248
243
        """
 
244
        # mutter("lock write: %s (%s)", self, self._lock_count)
249
245
        # TODO: Upgrade locking to support using a Transport,
250
246
        # and potentially a remote locking protocol
251
247
        if self._lock_mode:
256
252
            return self._token_from_lock
257
253
        else:
258
254
            token_from_lock = self._lock.lock_write(token=token)
 
255
            #note('write locking %s', self)
259
256
            #traceback.print_stack()
260
257
            self._lock_mode = 'w'
261
258
            self._lock_count = 1
264
261
            return token_from_lock
265
262
 
266
263
    def lock_read(self):
 
264
        # mutter("lock read: %s (%s)", self, self._lock_count)
267
265
        if self._lock_mode:
268
266
            if self._lock_mode not in ('r', 'w'):
269
267
                raise ValueError("invalid lock mode %r" % (self._lock_mode,))
270
268
            self._lock_count += 1
271
269
        else:
272
270
            self._lock.lock_read()
 
271
            #note('read locking %s', self)
273
272
            #traceback.print_stack()
274
273
            self._lock_mode = 'r'
275
274
            self._lock_count = 1
278
277
            self.get_transaction().set_cache_size(5000)
279
278
                        
280
279
    def unlock(self):
 
280
        # mutter("unlock: %s (%s)", self, self._lock_count)
281
281
        if not self._lock_mode:
282
282
            raise errors.LockNotHeld(self)
283
283
        if self._lock_count > 1:
284
284
            self._lock_count -= 1
285
285
        else:
 
286
            #note('unlocking %s', self)
286
287
            #traceback.print_stack()
287
288
            self._finish_transaction()
288
289
            try: