~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 20:27:42 UTC
  • mto: (2399.1.15 doc-cleanup)
  • mto: This revision was merged to the branch mainline in revision 2431.
  • Revision ID: john@arbash-meinel.com-20070412202742-4cr2qmchdfe9mg7n
Cherrypick just the epydoc builder changes.
This is just the piece of change that makes 'make api-docs' work,
without any actual documentation changes.

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