示例#1
0
    def copy(self, src_path, dest_name, **options):
        """Copy a given key to the given path."""
        if self.dry_run:
            return

        key = boto.s3.key.Key(self.get_connection())
        key.key = src_path
        key.copy(self.name, dest_name, **options)
示例#2
0
文件: stage.py 项目: atsansone/mut
    def copy(self, src_path: str, dest_name: str, **options) -> None:
        """Copy a given key to the given path."""
        if self.dry_run:
            return

        key = boto.s3.key.Key(self.get_connection())
        key.key = src_path
        key.copy(self.name, dest_name, **options)
示例#3
0
def copy_legacy_content_to_new_location(youtube_id):
    """Copy MP4 & PNG files from a legacy-format video to new naming scheme.
    """
    for key in converted_bucket.list(prefix="{0}/".format(youtube_id)):
        legacy_match = re_legacy_video_key_name.match(key.name)
        assert legacy_match is not None
        assert legacy_match.group(1) == youtube_id
        dest_key = "{0}.mp4/{1}".format(youtube_id, legacy_match.group(2))
        util.logger.info("Copying {0} to {1}".format(key.name, dest_key))
        key.copy(converted_bucket.name, dest_key, preserve_acl=True)
示例#4
0
  def copy(self, source, target, delete_source = False):
    '''Copy a single file from source to target using boto S3 library.'''
    source_url = S3URL(source)
    target_url = S3URL(target)

    if not self.opt.dry_run:
      bucket = self.s3.lookup(source_url.bucket, validate=self.opt.validate)
      key = bucket.get_key(source_url.path)
      key.copy(target_url.bucket, target_url.path)
      if delete_source:
        key.delete()
    message('%s => %s' % (source, target))
示例#5
0
  def copy(self, source, target, delete_source = False):
    '''Copy a single file from source to target using boto S3 library.'''
    source_url = S3URL(source)
    target_url = S3URL(target)

    if not self.opt.dry_run:
      bucket = self.s3.lookup(source_url.bucket, validate=self.opt.validate)
      key = bucket.get_key(source_url.path)
      key.copy(target_url.bucket, target_url.path)
      if delete_source:
        key.delete()
    message('%s => %s' % (source, target))
示例#6
0
 def stream_write(self, path, fp):
     # Minimum size of upload part size on S3 is 5MB
     buffer_size = 5 * 1024 * 1024
     if self.buffer_size > buffer_size:
         buffer_size = self.buffer_size
     path = self._init_path(path)
     tmp_path = "tmp/%s" % path
     mp = self._boto_bucket.initiate_multipart_upload(
         tmp_path, encrypt_key=(self._config.s3_encrypt is True))
     num_part = 1
     try:
         while True:
             buf = fp.read(buffer_size)
             if not buf:
                 break
             io = compat.StringIO(buf)
             mp.upload_part_from_file(io, num_part)
             num_part += 1
             io.close()
     except IOError as e:
         raise e
     mp.complete_upload()
     # do this to get the etag correct as the md5
     key = self.makeKey(tmp_path)
     if not key.exists():
         raise IOError('No such key: \'{0}\''.format(path))
     new_key = key.copy(self._config.boto_bucket, path)
     if not new_key.exists():
         raise IOError('No such key: \'{0}\''.format(path + "-tmp"))
     key.delete()