221
221
yield self.get(relpath)
224
def put(self, relpath, f):
224
def put(self, relpath, f, mode=None):
225
225
"""Copy the file-like or string object into the location.
227
227
:param relpath: Location to put the contents, relative to base.
228
228
:param f: File-like or string object.
229
:param mode: The mode for the newly created file,
230
None means just use the default
230
232
raise NotImplementedError
232
def put_multi(self, files, pb=None):
234
def put_multi(self, files, mode=None, pb=None):
233
235
"""Put a set of files or strings into the location.
235
237
:param files: A list of tuples of relpath, file object [(path1, file1), (path2, file2),...]
236
238
:param pb: An optional ProgressBar for indicating percent done.
239
:param mode: The mode for the newly created files
237
240
:return: The number of files copied.
239
return self._iterate_over(files, self.put, pb, 'put', expand=True)
243
self.put(path, f, mode=mode)
244
return self._iterate_over(files, put, pb, 'put', expand=True)
241
def mkdir(self, relpath):
246
def mkdir(self, relpath, mode=None):
242
247
"""Create a directory at the given path."""
243
248
raise NotImplementedError
245
def mkdir_multi(self, relpaths, pb=None):
250
def mkdir_multi(self, relpaths, mode=None, pb=None):
246
251
"""Create a group of directories"""
247
return self._iterate_over(relpaths, self.mkdir, pb, 'mkdir', expand=False)
253
self.mkdir(path, mode=mode)
254
return self._iterate_over(relpaths, mkdir, pb, 'mkdir', expand=False)
249
256
def append(self, relpath, f):
250
257
"""Append the text in the file-like or string object to
274
281
# implementors don't have to implement everything.
275
282
return self._iterate_over(relpaths, self.copy, pb, 'copy', expand=True)
277
def copy_to(self, relpaths, other, pb=None):
284
def copy_to(self, relpaths, other, mode=None, pb=None):
278
285
"""Copy a set of entries from self into another Transport.
280
287
:param relpaths: A list/generator of entries to be copied.
288
:param mode: This is the target mode for the newly created files
281
289
TODO: This interface needs to be updated so that the target location
282
290
can be different from the source location.
284
292
# The dummy implementation just does a simple get + put
285
293
def copy_entry(path):
286
other.put(path, self.get(path))
294
other.put(path, self.get(path), mode=mode)
288
296
return self._iterate_over(relpaths, copy_entry, pb, 'copy_to', expand=False)