~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/smart/vfs.py

  • Committer: John Arbash Meinel
  • Date: 2007-04-12 21:33:07 UTC
  • mfrom: (2413.4.1 api-doc-builders)
  • mto: This revision was merged to the branch mainline in revision 2566.
  • Revision ID: john@arbash-meinel.com-20070412213307-kuh07cnzaud12wx1
[merge] api-doc-builder and remove the pydoctor build code for now.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2010 Canonical Ltd
 
1
# Copyright (C) 2006, 2007 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
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
"""VFS operations for the smart server.
18
18
 
27
27
import os
28
28
 
29
29
from bzrlib import errors
30
 
from bzrlib import urlutils
31
30
from bzrlib.smart import request
32
31
 
33
32
 
52
51
 
53
52
class VfsRequest(request.SmartServerRequest):
54
53
    """Base class for VFS requests.
55
 
 
 
54
    
56
55
    VFS requests are disabled if vfs_enabled() returns False.
57
56
    """
58
57
 
60
59
        if not vfs_enabled():
61
60
            raise errors.DisabledMethod(self.__class__.__name__)
62
61
 
63
 
    def translate_client_path(self, relpath):
64
 
        # VFS requests are made with escaped paths so the escaping done in
65
 
        # SmartServerRequest.translate_client_path leads to double escaping.
66
 
        # Remove it here -- the fact that the result is still escaped means
67
 
        # that the str() will not fail on valid input.
68
 
        x = request.SmartServerRequest.translate_client_path(self, relpath)
69
 
        return str(urlutils.unescape(x))
70
 
 
71
62
 
72
63
class HasRequest(VfsRequest):
73
64
 
74
65
    def do(self, relpath):
75
 
        relpath = self.translate_client_path(relpath)
76
66
        r = self._backing_transport.has(relpath) and 'yes' or 'no'
77
 
        return request.SuccessfulSmartServerResponse((r,))
 
67
        return request.SmartServerResponse((r,))
78
68
 
79
69
 
80
70
class GetRequest(VfsRequest):
81
71
 
82
72
    def do(self, relpath):
83
 
        relpath = self.translate_client_path(relpath)
84
73
        backing_bytes = self._backing_transport.get_bytes(relpath)
85
 
        return request.SuccessfulSmartServerResponse(('ok',), backing_bytes)
 
74
        return request.SmartServerResponse(('ok',), backing_bytes)
86
75
 
87
76
 
88
77
class AppendRequest(VfsRequest):
89
78
 
90
79
    def do(self, relpath, mode):
91
 
        relpath = self.translate_client_path(relpath)
92
80
        self._relpath = relpath
93
81
        self._mode = _deserialise_optional_mode(mode)
94
 
 
 
82
    
95
83
    def do_body(self, body_bytes):
96
84
        old_length = self._backing_transport.append_bytes(
97
85
            self._relpath, body_bytes, self._mode)
98
 
        return request.SuccessfulSmartServerResponse(('appended', '%d' % old_length))
 
86
        return request.SmartServerResponse(('appended', '%d' % old_length))
99
87
 
100
88
 
101
89
class DeleteRequest(VfsRequest):
102
90
 
103
91
    def do(self, relpath):
104
 
        relpath = self.translate_client_path(relpath)
105
92
        self._backing_transport.delete(relpath)
106
 
        return request.SuccessfulSmartServerResponse(('ok', ))
 
93
        return request.SmartServerResponse(('ok', ))
107
94
 
108
95
 
109
96
class IterFilesRecursiveRequest(VfsRequest):
110
97
 
111
98
    def do(self, relpath):
112
 
        if not relpath.endswith('/'):
113
 
            relpath += '/'
114
 
        relpath = self.translate_client_path(relpath)
115
99
        transport = self._backing_transport.clone(relpath)
116
100
        filenames = transport.iter_files_recursive()
117
 
        return request.SuccessfulSmartServerResponse(('names',) + tuple(filenames))
 
101
        return request.SmartServerResponse(('names',) + tuple(filenames))
118
102
 
119
103
 
120
104
class ListDirRequest(VfsRequest):
121
105
 
122
106
    def do(self, relpath):
123
 
        if not relpath.endswith('/'):
124
 
            relpath += '/'
125
 
        relpath = self.translate_client_path(relpath)
126
107
        filenames = self._backing_transport.list_dir(relpath)
127
 
        return request.SuccessfulSmartServerResponse(('names',) + tuple(filenames))
 
108
        return request.SmartServerResponse(('names',) + tuple(filenames))
128
109
 
129
110
 
130
111
class MkdirRequest(VfsRequest):
131
112
 
132
113
    def do(self, relpath, mode):
133
 
        relpath = self.translate_client_path(relpath)
134
114
        self._backing_transport.mkdir(relpath,
135
115
                                      _deserialise_optional_mode(mode))
136
 
        return request.SuccessfulSmartServerResponse(('ok',))
 
116
        return request.SmartServerResponse(('ok',))
137
117
 
138
118
 
139
119
class MoveRequest(VfsRequest):
140
120
 
141
121
    def do(self, rel_from, rel_to):
142
 
        rel_from = self.translate_client_path(rel_from)
143
 
        rel_to = self.translate_client_path(rel_to)
144
122
        self._backing_transport.move(rel_from, rel_to)
145
 
        return request.SuccessfulSmartServerResponse(('ok',))
 
123
        return request.SmartServerResponse(('ok',))
146
124
 
147
125
 
148
126
class PutRequest(VfsRequest):
149
127
 
150
128
    def do(self, relpath, mode):
151
 
        relpath = self.translate_client_path(relpath)
152
129
        self._relpath = relpath
153
130
        self._mode = _deserialise_optional_mode(mode)
154
131
 
155
132
    def do_body(self, body_bytes):
156
133
        self._backing_transport.put_bytes(self._relpath, body_bytes, self._mode)
157
 
        return request.SuccessfulSmartServerResponse(('ok',))
 
134
        return request.SmartServerResponse(('ok',))
158
135
 
159
136
 
160
137
class PutNonAtomicRequest(VfsRequest):
161
138
 
162
139
    def do(self, relpath, mode, create_parent, dir_mode):
163
 
        relpath = self.translate_client_path(relpath)
164
140
        self._relpath = relpath
165
141
        self._dir_mode = _deserialise_optional_mode(dir_mode)
166
142
        self._mode = _deserialise_optional_mode(mode)
173
149
                mode=self._mode,
174
150
                create_parent_dir=self._create_parent,
175
151
                dir_mode=self._dir_mode)
176
 
        return request.SuccessfulSmartServerResponse(('ok',))
 
152
        return request.SmartServerResponse(('ok',))
177
153
 
178
154
 
179
155
class ReadvRequest(VfsRequest):
180
156
 
181
157
    def do(self, relpath):
182
 
        relpath = self.translate_client_path(relpath)
183
158
        self._relpath = relpath
184
159
 
185
160
    def do_body(self, body_bytes):
187
162
        offsets = self._deserialise_offsets(body_bytes)
188
163
        backing_bytes = ''.join(bytes for offset, bytes in
189
164
            self._backing_transport.readv(self._relpath, offsets))
190
 
        return request.SuccessfulSmartServerResponse(('readv',), backing_bytes)
 
165
        return request.SmartServerResponse(('readv',), backing_bytes)
191
166
 
192
167
    def _deserialise_offsets(self, text):
193
168
        # XXX: FIXME this should be on the protocol object.
203
178
class RenameRequest(VfsRequest):
204
179
 
205
180
    def do(self, rel_from, rel_to):
206
 
        rel_from = self.translate_client_path(rel_from)
207
 
        rel_to = self.translate_client_path(rel_to)
208
181
        self._backing_transport.rename(rel_from, rel_to)
209
 
        return request.SuccessfulSmartServerResponse(('ok', ))
 
182
        return request.SmartServerResponse(('ok', ))
210
183
 
211
184
 
212
185
class RmdirRequest(VfsRequest):
213
186
 
214
187
    def do(self, relpath):
215
 
        relpath = self.translate_client_path(relpath)
216
188
        self._backing_transport.rmdir(relpath)
217
 
        return request.SuccessfulSmartServerResponse(('ok', ))
 
189
        return request.SmartServerResponse(('ok', ))
218
190
 
219
191
 
220
192
class StatRequest(VfsRequest):
221
193
 
222
194
    def do(self, relpath):
223
 
        if not relpath.endswith('/'):
224
 
            relpath += '/'
225
 
        relpath = self.translate_client_path(relpath)
226
195
        stat = self._backing_transport.stat(relpath)
227
 
        return request.SuccessfulSmartServerResponse(
 
196
        return request.SmartServerResponse(
228
197
            ('stat', str(stat.st_size), oct(stat.st_mode)))
229
198