153
153
"""Does the target location exist?"""
154
154
raise NotImplementedError
156
def get(self, relpath):
156
def get(self, relpath, decode=False):
157
157
"""Get the file at the given relative path.
159
:param relpath: The relative path to the file
160
:param decode: If True, assume the file is utf-8 encoded and
161
decode it into Unicode
159
163
raise NotImplementedError
165
169
raise NotImplementedError
167
def get_multi(self, relpaths, pb=None):
171
def get_multi(self, relpaths, decode=False, pb=None):
168
172
"""Get a list of file-like objects, one for each entry in relpaths.
170
174
:param relpaths: A list of relative paths.
175
:param decode: If True, assume the file is utf-8 encoded and
176
decode it into Unicode
171
177
:param pb: An optional ProgressBar for indicating percent done.
172
178
:return: A list or generator of file-like objects
179
185
for relpath in relpaths:
180
186
self._update_pb(pb, 'get', count, total)
181
yield self.get(relpath)
187
yield self.get(relpath, decode=decode)
184
def put(self, relpath, f):
190
def put(self, relpath, f, encode=False):
185
191
"""Copy the file-like or string object into the location.
193
:param relpath: Location to put the contents, relative to base.
194
:param f: File-like or string object.
195
:param encode: If True, translate the contents into utf-8 encoded text.
187
197
raise NotImplementedError
189
def put_multi(self, files, pb=None):
199
def put_multi(self, files, encode=False, pb=None):
190
200
"""Put a set of files or strings into the location.
192
202
:param files: A list of tuples of relpath, file object [(path1, file1), (path2, file2),...]
193
203
:param pb: An optional ProgressBar for indicating percent done.
194
204
:return: The number of files copied.
196
return self._iterate_over(files, self.put, pb, 'put', expand=True)
207
self.put(relpath, f, encode=encode)
208
return self._iterate_over(files, put, pb, 'put', expand=True)
198
210
def mkdir(self, relpath):
199
211
"""Create a directory at the given path."""
200
212
raise NotImplementedError
202
def open(self, relpath, mode='wb'):
203
"""Open a remote file for writing.
204
This may return a proxy object, which is written to locally, and
205
then when the file is closed, it is uploaded using put()
207
raise NotImplementedError
209
214
def append(self, relpath, f):
210
215
"""Append the text in the file-like or string object to
211
216
the supplied location.