483
502
yield self.get(relpath)
505
@deprecated_method(zero_eleven)
486
506
def put(self, relpath, f, mode=None):
487
"""Copy the file-like or string object into the location.
507
"""Copy the file-like object into the location.
489
509
:param relpath: Location to put the contents, relative to base.
490
:param f: File-like or string object.
510
:param f: File-like object.
491
511
:param mode: The mode for the newly created file,
492
512
None means just use the default
494
raise NotImplementedError(self.put)
514
if isinstance(f, str):
515
return self.put_bytes(relpath, f, mode=mode)
517
return self.put_file(relpath, f, mode=mode)
519
def put_bytes(self, relpath, bytes, mode=None):
520
"""Atomically put the supplied bytes into the given location.
522
:param relpath: The location to put the contents, relative to the
524
:param bytes: A bytestring of data.
525
:param mode: Create the file with the given mode.
528
assert isinstance(bytes, str), \
529
'bytes must be a plain string, not %s' % type(bytes)
530
return self.put_file(relpath, StringIO(bytes), mode=mode)
532
def put_bytes_non_atomic(self, relpath, bytes, mode=None,
533
create_parent_dir=False,
535
"""Copy the string into the target location.
537
This function is not strictly safe to use. See
538
Transport.put_bytes_non_atomic for more information.
540
:param relpath: The remote location to put the contents.
541
:param bytes: A string object containing the raw bytes to write into
543
:param mode: Possible access permissions for new file.
544
None means do not set remote permissions.
545
:param create_parent_dir: If we cannot create the target file because
546
the parent directory does not exist, go ahead and
547
create it, and then try again.
548
:param dir_mode: Possible access permissions for new directories.
550
assert isinstance(bytes, str), \
551
'bytes must be a plain string, not %s' % type(bytes)
552
self.put_file_non_atomic(relpath, StringIO(bytes), mode=mode,
553
create_parent_dir=create_parent_dir,
556
def put_file(self, relpath, f, mode=None):
557
"""Copy the file-like object into the location.
559
:param relpath: Location to put the contents, relative to base.
560
:param f: File-like object.
561
:param mode: The mode for the newly created file,
562
None means just use the default.
564
# We would like to mark this as NotImplemented, but most likely
565
# transports have defined it in terms of the old api.
566
symbol_versioning.warn('Transport %s should implement put_file,'
567
' rather than implementing put() as of'
569
% (self.__class__.__name__,),
571
return self.put(relpath, f, mode=mode)
572
#raise NotImplementedError(self.put_file)
574
def put_file_non_atomic(self, relpath, f, mode=None,
575
create_parent_dir=False,
577
"""Copy the file-like object into the target location.
579
This function is not strictly safe to use. It is only meant to
580
be used when you already know that the target does not exist.
581
It is not safe, because it will open and truncate the remote
582
file. So there may be a time when the file has invalid contents.
584
:param relpath: The remote location to put the contents.
585
:param f: File-like object.
586
:param mode: Possible access permissions for new file.
587
None means do not set remote permissions.
588
:param create_parent_dir: If we cannot create the target file because
589
the parent directory does not exist, go ahead and
590
create it, and then try again.
591
:param dir_mode: Possible access permissions for new directories.
593
# Default implementation just does an atomic put.
595
return self.put_file(relpath, f, mode=mode)
596
except errors.NoSuchFile:
597
if not create_parent_dir:
599
parent_dir = osutils.dirname(relpath)
601
self.mkdir(parent_dir, mode=dir_mode)
602
return self.put_file(relpath, f, mode=mode)
604
@deprecated_method(zero_eleven)
496
605
def put_multi(self, files, mode=None, pb=None):
497
606
"""Put a set of files into the location.
515
627
self.mkdir(path, mode=mode)
516
628
return len(self._iterate_over(relpaths, mkdir, pb, 'mkdir', expand=False))
630
@deprecated_method(zero_eleven)
518
631
def append(self, relpath, f, mode=None):
519
"""Append the text in the file-like or string object to
520
the supplied location.
632
"""Append the text in the file-like object to the supplied location.
522
returns the length of f before the content was written to it.
634
returns the length of relpath before the content was written to it.
524
636
If the file does not exist, it is created with the supplied mode.
526
raise NotImplementedError(self.append)
638
return self.append_file(relpath, f, mode=mode)
640
def append_file(self, relpath, f, mode=None):
641
"""Append bytes from a file-like object to a file at relpath.
643
The file is created if it does not already exist.
645
:param f: a file-like object of the bytes to append.
646
:param mode: Unix mode for newly created files. This is not used for
649
:returns: the length of relpath before the content was written to it.
651
symbol_versioning.warn('Transport %s should implement append_file,'
652
' rather than implementing append() as of'
654
% (self.__class__.__name__,),
656
return self.append(relpath, f, mode=mode)
658
def append_bytes(self, relpath, bytes, mode=None):
659
"""Append bytes to a file at relpath.
661
The file is created if it does not already exist.
664
:param f: a string of the bytes to append.
665
:param mode: Unix mode for newly created files. This is not used for
668
:returns: the length of relpath before the content was written to it.
670
assert isinstance(bytes, str), \
671
'bytes must be a plain string, not %s' % type(bytes)
672
return self.append_file(relpath, StringIO(bytes), mode=mode)
528
674
def append_multi(self, files, pb=None):
529
675
"""Append the text in each file-like or string object to