/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/lockable_files.py

Merge bzr.dev and resolve conflicts.

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
import bzrlib.errors as errors
26
26
from bzrlib.errors import BzrError
27
27
from bzrlib.osutils import file_iterator, safe_unicode
28
 
from bzrlib.symbol_versioning import (deprecated_method,
29
 
        )
 
28
from bzrlib.symbol_versioning import (
 
29
    deprecated_in,
 
30
    deprecated_method,
 
31
    )
30
32
from bzrlib.trace import mutter, note
31
33
import bzrlib.transactions as transactions
32
34
import bzrlib.urlutils as urlutils
57
59
    the object is constructed.  In older formats OSLocks are used everywhere.
58
60
    in newer formats a LockDir is used for Repositories and Branches, and 
59
61
    OSLocks for the local filesystem.
 
62
 
 
63
    This class is now deprecated; code should move to using the Transport 
 
64
    directly for file operations and using the lock or CountedLock for 
 
65
    locking.
60
66
    """
61
67
 
62
68
    # _lock_mode: None, or 'r' or 'w'
64
70
    # _lock_count: If _lock_mode is true, a positive count of the number of
65
71
    # times the lock has been taken *by this process*.   
66
72
    
67
 
    # If set to False (by a plugin, etc) BzrBranch will not set the
68
 
    # mode on created files or directories
69
 
    _set_file_mode = True
70
 
    _set_dir_mode = True
71
 
 
72
73
    def __init__(self, transport, lock_name, lock_class):
73
74
        """Create a LockableFiles group
74
75
 
124
125
        return urlutils.escape(safe_unicode(file_or_path))
125
126
 
126
127
    def _find_modes(self):
127
 
        """Determine the appropriate modes for files and directories."""
 
128
        """Determine the appropriate modes for files and directories.
 
129
        
 
130
        :deprecated: Replaced by BzrDir._find_modes.
 
131
        """
128
132
        try:
129
133
            st = self._transport.stat('.')
130
134
        except errors.TransportNotPossible:
138
142
            self._dir_mode = (st.st_mode & 07777) | 00700
139
143
            # Remove the sticky and execute bits for files
140
144
            self._file_mode = self._dir_mode & ~07111
141
 
        if not self._set_dir_mode:
142
 
            self._dir_mode = None
143
 
        if not self._set_file_mode:
144
 
            self._file_mode = None
145
145
 
 
146
    @deprecated_method(deprecated_in((1, 6, 0)))
146
147
    def controlfilename(self, file_or_path):
147
 
        """Return location relative to branch."""
 
148
        """Return location relative to branch.
 
149
        
 
150
        :deprecated: Use Transport methods instead.
 
151
        """
148
152
        return self._transport.abspath(self._escape(file_or_path))
149
153
 
150
154
    @needs_read_lock
 
155
    @deprecated_method(deprecated_in((1, 5, 0)))
151
156
    def get(self, relpath):
152
 
        """Get a file as a bytestream."""
 
157
        """Get a file as a bytestream.
 
158
        
 
159
        :deprecated: Use a Transport instead of LockableFiles.
 
160
        """
153
161
        relpath = self._escape(relpath)
154
162
        return self._transport.get(relpath)
155
163
 
156
164
    @needs_read_lock
 
165
    @deprecated_method(deprecated_in((1, 5, 0)))
157
166
    def get_utf8(self, relpath):
158
 
        """Get a file as a unicode stream."""
 
167
        """Get a file as a unicode stream.
 
168
        
 
169
        :deprecated: Use a Transport instead of LockableFiles.
 
170
        """
159
171
        relpath = self._escape(relpath)
160
172
        # DO NOT introduce an errors=replace here.
161
173
        return codecs.getreader('utf-8')(self._transport.get(relpath))
162
174
 
163
175
    @needs_write_lock
 
176
    @deprecated_method(deprecated_in((1, 6, 0)))
164
177
    def put(self, path, file):
165
178
        """Write a file.
166
179
        
167
180
        :param path: The path to put the file, relative to the .bzr control
168
181
                     directory
169
 
        :param f: A file-like or string object whose contents should be copied.
 
182
        :param file: A file-like or string object whose contents should be copied.
 
183
 
 
184
        :deprecated: Use Transport methods instead.
170
185
        """
171
186
        self._transport.put_file(self._escape(path), file, mode=self._file_mode)
172
187
 
173
188
    @needs_write_lock
 
189
    @deprecated_method(deprecated_in((1, 6, 0)))
174
190
    def put_bytes(self, path, a_string):
175
191
        """Write a string of bytes.
176
192
 
177
193
        :param path: The path to put the bytes, relative to the transport root.
178
 
        :param string: A string object, whose exact bytes are to be copied.
 
194
        :param a_string: A string object, whose exact bytes are to be copied.
 
195
 
 
196
        :deprecated: Use Transport methods instead.
179
197
        """
180
198
        self._transport.put_bytes(self._escape(path), a_string,
181
199
                                  mode=self._file_mode)
182
200
 
183
201
    @needs_write_lock
 
202
    @deprecated_method(deprecated_in((1, 6, 0)))
184
203
    def put_utf8(self, path, a_string):
185
204
        """Write a string, encoding as utf-8.
186
205
 
187
206
        :param path: The path to put the string, relative to the transport root.
188
207
        :param string: A string or unicode object whose contents should be copied.
 
208
 
 
209
        :deprecated: Use Transport methods instead.
189
210
        """
190
211
        # IterableFile would not be needed if Transport.put took iterables
191
212
        # instead of files.  ADHB 2005-12-25
242
263
    def lock_read(self):
243
264
        # mutter("lock read: %s (%s)", self, self._lock_count)
244
265
        if self._lock_mode:
245
 
            assert self._lock_mode in ('r', 'w'), \
246
 
                   "invalid lock mode %r" % self._lock_mode
 
266
            if self._lock_mode not in ('r', 'w'):
 
267
                raise ValueError("invalid lock mode %r" % (self._lock_mode,))
247
268
            self._lock_count += 1
248
269
        else:
249
270
            self._lock.lock_read()