483
498
yield self.get(relpath)
501
@deprecated_method(zero_eleven)
486
502
def put(self, relpath, f, mode=None):
487
"""Copy the file-like or string object into the location.
503
"""Copy the file-like object into the location.
489
505
:param relpath: Location to put the contents, relative to base.
490
:param f: File-like or string object.
506
:param f: File-like object.
491
507
:param mode: The mode for the newly created file,
492
508
None means just use the default
494
raise NotImplementedError(self.put)
510
if isinstance(f, str):
511
return self.put_bytes(relpath, f, mode=mode)
513
return self.put_file(relpath, f, mode=mode)
515
def put_bytes(self, relpath, bytes, mode=None):
516
"""Atomically put the supplied bytes into the given location.
518
:param relpath: The location to put the contents, relative to the
520
:param bytes: A bytestring of data.
521
:param mode: Create the file with the given mode.
524
assert isinstance(bytes, str), \
525
'bytes must be a plain string, not %s' % type(bytes)
526
return self.put_file(relpath, StringIO(bytes), mode=mode)
528
def put_bytes_non_atomic(self, relpath, bytes, mode=None,
529
create_parent_dir=False,
531
"""Copy the string into the target location.
533
This function is not strictly safe to use. See
534
Transport.put_bytes_non_atomic for more information.
536
:param relpath: The remote location to put the contents.
537
:param bytes: A string object containing the raw bytes to write into
539
:param mode: Possible access permissions for new file.
540
None means do not set remote permissions.
541
:param create_parent_dir: If we cannot create the target file because
542
the parent directory does not exist, go ahead and
543
create it, and then try again.
544
:param dir_mode: Possible access permissions for new directories.
546
assert isinstance(bytes, str), \
547
'bytes must be a plain string, not %s' % type(bytes)
548
self.put_file_non_atomic(relpath, StringIO(bytes), mode=mode,
549
create_parent_dir=create_parent_dir,
552
def put_file(self, relpath, f, mode=None):
553
"""Copy the file-like object into the location.
555
:param relpath: Location to put the contents, relative to base.
556
:param f: File-like object.
557
:param mode: The mode for the newly created file,
558
None means just use the default.
560
# We would like to mark this as NotImplemented, but most likely
561
# transports have defined it in terms of the old api.
562
symbol_versioning.warn('Transport %s should implement put_file,'
563
' rather than implementing put() as of'
565
% (self.__class__.__name__,),
567
return self.put(relpath, f, mode=mode)
568
#raise NotImplementedError(self.put_file)
570
def put_file_non_atomic(self, relpath, f, mode=None,
571
create_parent_dir=False,
573
"""Copy the file-like object into the target location.
575
This function is not strictly safe to use. It is only meant to
576
be used when you already know that the target does not exist.
577
It is not safe, because it will open and truncate the remote
578
file. So there may be a time when the file has invalid contents.
580
:param relpath: The remote location to put the contents.
581
:param f: File-like object.
582
:param mode: Possible access permissions for new file.
583
None means do not set remote permissions.
584
:param create_parent_dir: If we cannot create the target file because
585
the parent directory does not exist, go ahead and
586
create it, and then try again.
587
:param dir_mode: Possible access permissions for new directories.
589
# Default implementation just does an atomic put.
591
return self.put_file(relpath, f, mode=mode)
592
except errors.NoSuchFile:
593
if not create_parent_dir:
595
parent_dir = osutils.dirname(relpath)
597
self.mkdir(parent_dir, mode=dir_mode)
598
return self.put_file(relpath, f, mode=mode)
600
@deprecated_method(zero_eleven)
496
601
def put_multi(self, files, mode=None, pb=None):
497
602
"""Put a set of files into the location.
515
623
self.mkdir(path, mode=mode)
516
624
return len(self._iterate_over(relpaths, mkdir, pb, 'mkdir', expand=False))
626
@deprecated_method(zero_eleven)
518
627
def append(self, relpath, f, mode=None):
519
"""Append the text in the file-like or string object to
520
the supplied location.
522
returns the length of f before the content was written to it.
524
If the file does not exist, it is created with the supplied mode.
526
raise NotImplementedError(self.append)
628
"""Append the text in the file-like object to the supplied location.
630
returns the length of relpath before the content was written to it.
632
If the file does not exist, it is created with the supplied mode.
634
return self.append_file(relpath, f, mode=mode)
636
def append_file(self, relpath, f, mode=None):
637
"""Append the text in the file-like object to the supplied location.
639
returns the length of relpath before the content was written to it.
641
If the file does not exist, it is created with the supplied mode.
643
symbol_versioning.warn('Transport %s should implement append_file,'
644
' rather than implementing append() as of'
646
% (self.__class__.__name__,),
648
return self.append(relpath, f, mode=mode)
650
def append_bytes(self, relpath, bytes, mode=None):
651
"""Append the text in the string object to the supplied location.
653
returns the length of relpath before the content was written to it.
655
If the file does not exist, it is created with the supplied mode.
657
assert isinstance(bytes, str), \
658
'bytes must be a plain string, not %s' % type(bytes)
659
return self.append_file(relpath, StringIO(bytes), mode=mode)
528
661
def append_multi(self, files, pb=None):
529
662
"""Append the text in each file-like or string object to