123
123
def abspath(self, relpath):
124
124
"""Return the full url to the given relative path.
125
125
This can be supplied with a string or a list
127
XXX: Robert Collins 20051016 - is this really needed in the public
127
130
raise NotImplementedError
129
132
def relpath(self, abspath):
130
133
"""Return the local path portion from a given absolute path.
135
This default implementation is not suitable for filesystems with
136
aliasing, such as that given by symlinks, where a path may not
137
start with our base, but still be a relpath once aliasing is
132
raise NotImplementedError
140
if not abspath.startswith(self.base):
141
raise NonRelativePath('path %r is not under base URL %r'
142
% (abspath, self.base))
144
return abspath[pl:].lstrip('/')
134
147
def has(self, relpath):
135
"""Does the target location exist?"""
148
"""Does the file relpath exist?
150
Note that some transports MAY allow querying on directories, but this
151
is not part of the protocol.
136
153
raise NotImplementedError
138
155
def has_multi(self, relpaths, pb=None):
144
161
yield self.has(relpath)
164
def iter_files_recursive(self):
165
"""Iter the relative paths of files in the transports sub-tree.
167
As with other listing functions, only some transports implement this,.
168
you may check via is_listable to determine if it will.
170
raise NotImplementedError
147
172
def get(self, relpath):
148
173
"""Get the file at the given relative path.
168
193
yield self.get(relpath)
171
def get_partial(self, relpath, start, length=None):
172
"""Get just part of a file.
174
:param relpath: Path to the file, relative to base
175
:param start: The starting position to read from
176
:param length: The length to read. A length of None indicates
177
read to the end of the file.
178
:return: A file-like object containing at least the specified bytes.
179
Some implementations may return objects which can be read
180
past this length, but this is not guaranteed.
182
raise NotImplementedError
184
def get_partial_multi(self, offsets, pb=None):
185
"""Put a set of files or strings into the location.
187
Requesting multiple portions of the same file can be dangerous.
189
:param offsets: A list of tuples of relpath, start, length
190
[(path1, start1, length1),
191
(path2, start2, length2),
192
(path3, start3), ...]
193
length is optional, defaulting to None
194
:param pb: An optional ProgressBar for indicating percent done.
195
:return: A generator of file-like objects.
197
total = self._get_total(offsets)
199
for offset in offsets:
200
self._update_pb(pb, 'get_partial', count, total)
201
yield self.get_partial(*offset)
204
196
def put(self, relpath, f):
205
197
"""Copy the file-like or string object into the location.
302
294
"""Return the stat information for a file.
303
295
WARNING: This may not be implementable for all protocols, so use
297
NOTE: This returns an object with fields such as 'st_size'. It MAY
298
or MAY NOT return the literal result of an os.stat() call, so all
299
access should be via named fields.
300
ALSO NOTE: Stats of directories may not be supported on some
306
303
raise NotImplementedError