write the buffer to modified_file.

    modified_file should be in the format 's3://bucketname/path/to/file.txt'
176563
def put_file(buffer, modified_file):
    
    import mimetypes
    import boto3
    file_type, _ = mimetypes.guess_type(modified_file)

    s3 = boto3.resource('s3')
    bucket_name, object_key = _parse_s3_file(modified_file)
    extra_args = {
        'ACL': 'public-read',
        'ContentType': file_type
    }
    bucket = s3.Bucket(bucket_name)
    logger.info("Uploading {0} to {1}".format(object_key, bucket_name))
    bucket.upload_fileobj(buffer, object_key, ExtraArgs=extra_args)
1154653
def upload(s3_conn, filepath, s3_path):
    
    bucket_name, prefix = split_s3_path(s3_path)
    bucket = s3_conn.get_bucket(bucket_name)
    filename = os.path.basename(filepath)

    key = boto.s3.key.Key(
        bucket=bucket,
        name='{}/{}'.format(prefix, filename)
    )
    logging.info('uploading from %s to %s', filepath, key)
    key.set_contents_from_filename(filepath)
1326531
def _file_write(path, content):
    '''
    
    '''
    with salt.utils.files.fopen(path, 'w+') as fp_:
        fp_.write(salt.utils.stringutils.to_str(content))
    fp_.close()
1185980
def WriteFileHash(self, path, hash_value):
    
    string = '{0:s}\t{1:s}\n'.format(hash_value, path)

    encoded_string = self._EncodeString(string)
    self._file_object.write(encoded_string)
1150878
def save(self, file_path):
        
        if os.path.isfile(file_path):
            with open(self.get_backup_file_name(file_path), 'w') as d:
                with open(file_path, 'r') as o:
                    d.write(o.read())
        elif os.path.exists(file_path):
            raise XonoticDBException('%s exists and is not a file. Cannot write to it.', file_path)
        lines = [''] * self.db_buckets
        for key, value in self.items():
            lines[self.hashfunc(key) % self.db_buckets] += r'\%s\%s' % (key, urllib.parse.quote(value))
        with open(file_path, 'w') as f:
            f.write('%d\n' % self.db_buckets)
            for i in lines:
                f.write(i + '\n')
1322396
def do_write(self):
        
        while True:
            try:
                written = 0

                if hasattr(self.fd, 'send'):
                    written = self.fd.send(self.buffer)
                else:
                    written = os.write(self.fd.fileno(), self.buffer)

                self.buffer = self.buffer[written:]

                # try to close after writes if a close was requested
                if self.close_requested and len(self.buffer) == 0:
                    self.close()

                return written
            except EnvironmentError as e:
                if e.errno not in Stream.ERRNO_RECOVERABLE:
                    raise e
688117
def upload_to_s3(self, region='us-east-1'):
        
        s3_import_cmd = "aws s3 cp {} s3://{} --profile '{}' --region {}".format(self.upload_file, self.bucket_name,
                                                                                 self.aws_project, region)
        print "Uploading to bucket {} in s3 with the cmd: {}".format(self.bucket_name, s3_import_cmd)
        # s3 upload puts DL progress to stderr
        s3_upload = subprocess.Popen(shlex.split(s3_import_cmd), stderr=subprocess.PIPE)
        while True:
            progress = s3_upload.stderr.readline()
            if progress == '' and s3_upload.poll() is not None:
                break
            if progress:
                print (progress)
        rc = s3_upload.poll()
        if rc != 0:
            raise subprocess.CalledProcessError(rc)
        print "Upload completed successfully"
1140799
def __write(self, s):
        
        self.buf += s
        while len(self.buf) > self.bufsize:
            self.fileobj.write(self.buf[:self.bufsize])
            self.buf = self.buf[self.bufsize:]
183096
private int writeAtMost(ByteBuffer data, int offset, int length)
    {
        if (current >= bufferOffset + buffer.length)
            reBuffer();

        assert current < bufferOffset + buffer.length
        : String.format("File (%s) offset %d, buffer offset %d.", getPath(), current, bufferOffset);


        int toCopy = Math.min(length, buffer.length - bufferCursor());

        // copy bytes from external buffer
        ByteBufferUtil.arrayCopy(data, offset, buffer, bufferCursor(), toCopy);

        assert current <= bufferOffset + buffer.length
        : String.format("File (%s) offset %d, buffer offset %d.", getPath(), current, bufferOffset);

        validBufferBytes = Math.max(validBufferBytes, bufferCursor() + toCopy);
        current += toCopy;

        return toCopy;
    }
1052889
def put(self, local_path, destination_s3_path, **kwargs):
        
        self._check_deprecated_argument(**kwargs)

        # put the file
        self.put_multipart(local_path, destination_s3_path, **kwargs)
1040764
def write(self, path):
        """"""
        with open(path, 'w') as fd:
            fd.write(json.dumps(
                {
                    "created_at": self._created_at,
                    "version": self._version,
                    "mtllibs": self._mtllibs,
                    "vertex_buffers": self._vertex_buffers,
                },
                indent=2,
            ))
623984
function writeFile(namespace, fileName, fileLocation) {
  var file;
  if (namespace) {
    file = path.join(namespace, fileName);
  } else {
    file = fileName;
  }
  var params = {
    localFile: fileLocation,
    ACL: CONSTANTS.AWS_BUCKET_PERMISSIONS,
    s3Params: {
      Bucket: config.bucket,
      Key: file
    }
  };
  var deferred = q.defer();
  var uploader = awsClient.uploadFile(params);
  uploader.on('error', function(err) {
    console.log(err);
    deferred.reject(err.stack);
  });
  uploader.on('end', function() {
    deferred.resolve(fileName);
  });
  return deferred.promise;
}
98752
def example_write_file_to_disk_if_changed():
    
    my_file = FileAsObj('/tmp/example_file.txt')
    my_file.rm(my_file.egrep('^#'))
    if my_file.changed:
        my_file.save()
617728
def write(data, path, saltenv='base', index=0):
    '''
    
    '''
    if saltenv not in __opts__['pillar_roots']:
        return 'Named environment {0} is not present'.format(saltenv)
    if len(__opts__['pillar_roots'][saltenv]) <= index:
        return 'Specified index {0} in environment {1} is not present'.format(
                index, saltenv)
    if os.path.isabs(path):
        return ('The path passed in {0} is not relative to the environment '
                '{1}').format(path, saltenv)
    dest = os.path.join(__opts__['pillar_roots'][saltenv][index], path)
    dest_dir = os.path.dirname(dest)
    if not os.path.isdir(dest_dir):
        os.makedirs(dest_dir)
    with salt.utils.files.fopen(dest, 'w+') as fp_:
        fp_.write(salt.utils.stringutils.to_str(data))
    return 'Wrote data to file {0}'.format(dest)
997792
def put_stream(self, rel_path, metadata=None, cb=None):
        ''' '''

        import Queue
        import time
        import threading

        md5 = metadata.get('md5', None) if metadata else None

        # Horrible, but doing it anyway because I can.
        acl = ('public-read' if metadata.get('public',
                                             False) else metadata.get('acl',
                                                                      'public-read')) if metadata else 'public-read'

        path = self._prefix(self._rename(rel_path))

        class ThreadUploader(threading.Thread):

            """Thread class for uploading a part to S3"""

            def __init__(self, n, queue):
                threading.Thread.__init__(self)
                self.n = n
                self.queue = queue

            def run(self):

                while True:
                    mp, part_number, buf = self.queue.get()
                    if mp is None:  # Signal to die
                        logger.debug(
                            "put_stream: Thread {} exiting".format(
                                self.n))
                        self.queue.task_done()
                        return
                    logger.debug(
                        "put_stream: Thread {}: processing part: {}".format(
                            self.n,
                            part_number))
                    t1 = time.time()
                    try:
                        mp.upload_part_from_file(buf, part_number)
                    finally:
                        self.queue.task_done()
                        t2 = time.time()
                        logger.debug("put_stream: Thread {}, part {}. time = {} rate =  {} b/s" .format(
                            self.n, part_number, round(t2 - t1, 3), round((float(buf.tell()) / (t2 - t1)), 2)))

        if metadata is None:
            metadata = {}

        if md5:
            metadata['md5'] = md5  # Multipart uploads don't use md5 for etag

        # Some libraries, including apparently, boto, have troubles properly calcing the hash when
        # metadata values are null, empty, 0, etc.
        # https://forums.aws.amazon.com/thread.jspa?threadID=117580
        for k, v in metadata.items():
            if not v:
                del metadata[k]

        this = self

        buffer_size = 50 * 1024 * 1024  # Min part size is 5MB
        num_threads = 4
        thread_upload_queue = Queue.Queue(maxsize=100)

        for i in range(num_threads):
            t = ThreadUploader(i, thread_upload_queue)
            t.setDaemon(True)
            t.start()

        class flo:

            '''Object that is returned to the caller, for the caller to issue
            write() or writeline() calls on '''

            def __init__(self, rel_path):
                import io

                self.mp = this.bucket.initiate_multipart_upload(
                    path,
                    metadata=metadata)
                self.part_number = 1
                self.buffer = io.BytesIO()
                self.total_size = 0

                self.rel_path = rel_path

            def _send_buffer(self):
                '''Schedules a buffer to be sent in a thread by queuing it'''
                logger.debug(
                    "_send_buffer: sending part {} to thread pool size: {}, total_size = {}" .format(
                        self.part_number,
                        self.buffer.tell(),
                        self.total_size))
                self.buffer.seek(0)
                thread_upload_queue.put(
                    (self.mp, self.part_number, self.buffer))

            def write(self, d):
                import io

                self.buffer.write(d)  # Load the requested data into a buffer
                self.total_size += len(d)
                # After the buffer is large enough, send it, then create a new
                # buffer.
                if self.buffer.tell() > buffer_size:
                    self._send_buffer()

                    self.part_number += 1
                    self.buffer = io.BytesIO()

            def writelines(self, lines):
                raise NotImplemented()

            def close(self):

                if self.buffer.tell() > 0:
                    self._send_buffer()

                # Wait for all of th upload to complete
                thread_upload_queue.join()

                for i in range(num_threads):
                    thread_upload_queue.put(
                        (None, None, None))  # Tell all of the threads to die

                # Wait for all of the threads to exit
                thread_upload_queue.join()

                # Multi-part uploads throw a 400 Bad Request if they are
                # completed without writing any data.
                if self.total_size > 0:
                    self.mp.complete_upload()

                    this.bucket.set_acl(acl, path)

                this.put_metadata(self.rel_path, metadata)

            def __enter__(self):
                return self

            def __exit__(self, type_, value, traceback):
                if type_:
                    return False

                self.close()

        return flo(rel_path)
1146256
def write(self, data):
    
    ctx = context.get()
    if len(data) != 2:
      logging.error("Got bad tuple of length %d (2-tuple expected): %s",
                    len(data), data)

    try:
      key = str(data[0])
      value = str(data[1])
    except TypeError:
      logging.error("Expecting a tuple, but got %s: %s",
                    data.__class__.__name__, data)

    file_index = key.__hash__() % len(self._filehandles)

    # Work-around: Since we don't have access to the context in the to_json()
    # function, but we need to flush each pool before we serialize the
    # filehandle, we rely on a member variable instead of using context for
    # pool management.
    pool = self._pools[file_index]
    if pool is None:
      filehandle = self._filehandles[file_index]
      pool = output_writers.GCSRecordsPool(filehandle=filehandle, ctx=ctx)
      self._pools[file_index] = pool

    proto = kv_pb.KeyValue()
    proto.set_key(key)
    proto.set_value(value)
    pool.append(proto.Encode())
562887
def write_path(path, s, owner=None, group=None, mode=None,
               utimes=None, sync=False):
    
    path = os.path.abspath(path)
    fd, tmp_path = tempfile.mkstemp(suffix='.tmp',
                                    prefix='.ansible_mitogen_transfer-',
                                    dir=os.path.dirname(path))
    fp = os.fdopen(fd, 'wb', mitogen.core.CHUNK_SIZE)
    LOG.debug('write_path(path=%r) temporary file: %s', path, tmp_path)

    try:
        try:
            if mode:
                set_file_mode(tmp_path, mode, fd=fp.fileno())
            if owner or group:
                set_file_owner(tmp_path, owner, group, fd=fp.fileno())
            fp.write(s)
        finally:
            fp.close()

        if sync:
            os.fsync(fp.fileno())
        os.rename(tmp_path, path)
    except BaseException:
        os.unlink(tmp_path)
        raise

    if utimes:
        os.utime(path, utimes)