~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/smart/vfs.py

  • Committer: Robert Collins
  • Date: 2007-04-19 02:27:44 UTC
  • mto: This revision was merged to the branch mainline in revision 2426.
  • Revision ID: robertc@robertcollins.net-20070419022744-pfdqz42kp1wizh43
``make docs`` now creates a man page at ``man1/bzr.1`` fixing bug 107388.
(Robert Collins)

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 
51
51
 
52
52
class VfsRequest(request.SmartServerRequest):
53
53
    """Base class for VFS requests.
54
 
 
 
54
    
55
55
    VFS requests are disabled if vfs_enabled() returns False.
56
56
    """
57
57
 
63
63
class HasRequest(VfsRequest):
64
64
 
65
65
    def do(self, relpath):
66
 
        relpath = self.translate_client_path(relpath)
67
66
        r = self._backing_transport.has(relpath) and 'yes' or 'no'
68
 
        return request.SuccessfulSmartServerResponse((r,))
 
67
        return request.SmartServerResponse((r,))
69
68
 
70
69
 
71
70
class GetRequest(VfsRequest):
72
71
 
73
72
    def do(self, relpath):
74
 
        relpath = self.translate_client_path(relpath)
75
73
        backing_bytes = self._backing_transport.get_bytes(relpath)
76
 
        return request.SuccessfulSmartServerResponse(('ok',), backing_bytes)
 
74
        return request.SmartServerResponse(('ok',), backing_bytes)
77
75
 
78
76
 
79
77
class AppendRequest(VfsRequest):
80
78
 
81
79
    def do(self, relpath, mode):
82
 
        relpath = self.translate_client_path(relpath)
83
80
        self._relpath = relpath
84
81
        self._mode = _deserialise_optional_mode(mode)
85
 
 
 
82
    
86
83
    def do_body(self, body_bytes):
87
84
        old_length = self._backing_transport.append_bytes(
88
85
            self._relpath, body_bytes, self._mode)
89
 
        return request.SuccessfulSmartServerResponse(('appended', '%d' % old_length))
 
86
        return request.SmartServerResponse(('appended', '%d' % old_length))
90
87
 
91
88
 
92
89
class DeleteRequest(VfsRequest):
93
90
 
94
91
    def do(self, relpath):
95
 
        relpath = self.translate_client_path(relpath)
96
92
        self._backing_transport.delete(relpath)
97
 
        return request.SuccessfulSmartServerResponse(('ok', ))
 
93
        return request.SmartServerResponse(('ok', ))
98
94
 
99
95
 
100
96
class IterFilesRecursiveRequest(VfsRequest):
101
97
 
102
98
    def do(self, relpath):
103
 
        if not relpath.endswith('/'):
104
 
            relpath += '/'
105
 
        relpath = self.translate_client_path(relpath)
106
99
        transport = self._backing_transport.clone(relpath)
107
100
        filenames = transport.iter_files_recursive()
108
 
        return request.SuccessfulSmartServerResponse(('names',) + tuple(filenames))
 
101
        return request.SmartServerResponse(('names',) + tuple(filenames))
109
102
 
110
103
 
111
104
class ListDirRequest(VfsRequest):
112
105
 
113
106
    def do(self, relpath):
114
 
        if not relpath.endswith('/'):
115
 
            relpath += '/'
116
 
        relpath = self.translate_client_path(relpath)
117
107
        filenames = self._backing_transport.list_dir(relpath)
118
 
        return request.SuccessfulSmartServerResponse(('names',) + tuple(filenames))
 
108
        return request.SmartServerResponse(('names',) + tuple(filenames))
119
109
 
120
110
 
121
111
class MkdirRequest(VfsRequest):
122
112
 
123
113
    def do(self, relpath, mode):
124
 
        relpath = self.translate_client_path(relpath)
125
114
        self._backing_transport.mkdir(relpath,
126
115
                                      _deserialise_optional_mode(mode))
127
 
        return request.SuccessfulSmartServerResponse(('ok',))
 
116
        return request.SmartServerResponse(('ok',))
128
117
 
129
118
 
130
119
class MoveRequest(VfsRequest):
131
120
 
132
121
    def do(self, rel_from, rel_to):
133
 
        rel_from = self.translate_client_path(rel_from)
134
 
        rel_to = self.translate_client_path(rel_to)
135
122
        self._backing_transport.move(rel_from, rel_to)
136
 
        return request.SuccessfulSmartServerResponse(('ok',))
 
123
        return request.SmartServerResponse(('ok',))
137
124
 
138
125
 
139
126
class PutRequest(VfsRequest):
140
127
 
141
128
    def do(self, relpath, mode):
142
 
        relpath = self.translate_client_path(relpath)
143
129
        self._relpath = relpath
144
130
        self._mode = _deserialise_optional_mode(mode)
145
131
 
146
132
    def do_body(self, body_bytes):
147
133
        self._backing_transport.put_bytes(self._relpath, body_bytes, self._mode)
148
 
        return request.SuccessfulSmartServerResponse(('ok',))
 
134
        return request.SmartServerResponse(('ok',))
149
135
 
150
136
 
151
137
class PutNonAtomicRequest(VfsRequest):
152
138
 
153
139
    def do(self, relpath, mode, create_parent, dir_mode):
154
 
        relpath = self.translate_client_path(relpath)
155
140
        self._relpath = relpath
156
141
        self._dir_mode = _deserialise_optional_mode(dir_mode)
157
142
        self._mode = _deserialise_optional_mode(mode)
164
149
                mode=self._mode,
165
150
                create_parent_dir=self._create_parent,
166
151
                dir_mode=self._dir_mode)
167
 
        return request.SuccessfulSmartServerResponse(('ok',))
 
152
        return request.SmartServerResponse(('ok',))
168
153
 
169
154
 
170
155
class ReadvRequest(VfsRequest):
171
156
 
172
157
    def do(self, relpath):
173
 
        relpath = self.translate_client_path(relpath)
174
158
        self._relpath = relpath
175
159
 
176
160
    def do_body(self, body_bytes):
178
162
        offsets = self._deserialise_offsets(body_bytes)
179
163
        backing_bytes = ''.join(bytes for offset, bytes in
180
164
            self._backing_transport.readv(self._relpath, offsets))
181
 
        return request.SuccessfulSmartServerResponse(('readv',), backing_bytes)
 
165
        return request.SmartServerResponse(('readv',), backing_bytes)
182
166
 
183
167
    def _deserialise_offsets(self, text):
184
168
        # XXX: FIXME this should be on the protocol object.
194
178
class RenameRequest(VfsRequest):
195
179
 
196
180
    def do(self, rel_from, rel_to):
197
 
        rel_from = self.translate_client_path(rel_from)
198
 
        rel_to = self.translate_client_path(rel_to)
199
181
        self._backing_transport.rename(rel_from, rel_to)
200
 
        return request.SuccessfulSmartServerResponse(('ok', ))
 
182
        return request.SmartServerResponse(('ok', ))
201
183
 
202
184
 
203
185
class RmdirRequest(VfsRequest):
204
186
 
205
187
    def do(self, relpath):
206
 
        relpath = self.translate_client_path(relpath)
207
188
        self._backing_transport.rmdir(relpath)
208
 
        return request.SuccessfulSmartServerResponse(('ok', ))
 
189
        return request.SmartServerResponse(('ok', ))
209
190
 
210
191
 
211
192
class StatRequest(VfsRequest):
212
193
 
213
194
    def do(self, relpath):
214
 
        if not relpath.endswith('/'):
215
 
            relpath += '/'
216
 
        relpath = self.translate_client_path(relpath)
217
195
        stat = self._backing_transport.stat(relpath)
218
 
        return request.SuccessfulSmartServerResponse(
 
196
        return request.SmartServerResponse(
219
197
            ('stat', str(stat.st_size), oct(stat.st_mode)))
220
198