示例#1
0
def write_csv_to_s3(data, is_owner, **kwargs):  # pragma: no cover
    cwd = cd_temp()
    csv_file = csv_file_for(data, **kwargs)
    csv_file.close()
    zip_file_name = csv_file.name + '.zip'
    with zipfile.ZipFile(zip_file_name, 'w', zipfile.ZIP_DEFLATED) as zip_file:
        zip_file.write(csv_file.name)

    file_path = get_downloads_path(is_owner) + zip_file_name
    S3.upload_file(file_path)
    os.chdir(cwd)
    return S3.url_for(file_path)
示例#2
0
def write_csv_to_s3(data, is_owner, **kwargs):
    cwd = cd_temp()
    csv_file = csv_file_for(data, **kwargs)
    csv_file.close()
    zip_file_name = csv_file.name + '.zip'
    with zipfile.ZipFile(zip_file_name, 'w', zipfile.ZIP_DEFLATED) as zip:
        zip.write(csv_file.name)

    bucket = S3ConnectionFactory.get_export_bucket()
    k = Key(bucket)
    _dir = 'downloads/creator/' if is_owner else 'downloads/reader/'
    k.key = _dir + zip_file_name
    k.set_contents_from_filename(zip_file_name)

    os.chdir(cwd)
    return bucket.get_key(k.key).generate_url(expires_in=60)
示例#3
0
def write_csv_to_s3(data, is_owner, **kwargs):
    cwd = cd_temp()
    csv_file = csv_file_for(data, **kwargs)
    csv_file.close()
    zip_file_name = csv_file.name + '.zip'
    with zipfile.ZipFile(zip_file_name, 'w', zipfile.ZIP_DEFLATED) as zip:
        zip.write(csv_file.name)

    bucket = S3ConnectionFactory.get_export_bucket()
    k = Key(bucket)
    _dir = 'downloads/creator/' if is_owner else 'downloads/reader/'
    k.key = _dir + zip_file_name
    k.set_contents_from_filename(zip_file_name)

    os.chdir(cwd)
    return bucket.get_key(k.key).generate_url(expires_in=60)
示例#4
0
def write_csv_to_s3(data, is_owner, **kwargs):  # pragma: no cover
    cwd = cd_temp()
    csv_file = csv_file_for(data, **kwargs)
    csv_file.close()
    zip_file_name = csv_file.name + '.zip'
    with zipfile.ZipFile(zip_file_name, 'w', zipfile.ZIP_DEFLATED) as zip_file:
        zip_file.write(csv_file.name)

    key = get_downloads_path(is_owner) + zip_file.filename
    S3.upload_file(key=key,
                   file_path=os.path.abspath(zip_file.filename),
                   binary=True,
                   metadata=dict(ContentType='application/zip'),
                   headers={'content-type': 'application/zip'})
    os.chdir(cwd)
    return S3.url_for(key)
示例#5
0
文件: utils.py 项目: AnshuAg/oclapi
def write_csv_to_s3(data, is_owner, **kwargs):
    cwd = cd_temp()
    csv_file = csv_file_for(data, **kwargs)
    csv_file.close()
    reader = open(os.path.abspath(csv_file.name), 'r')
    gz = gzip.open(csv_file.name + '.gz', 'wb')
    lines = reader.readlines()
    gz.writelines(lines)
    gz.close()
    reader.close()

    bucket = S3ConnectionFactory.get_export_bucket()
    k = Key(bucket)
    _dir = 'downloads/creator/' if is_owner else 'downloads/reader/'
    k.key = _dir + gz.name
    k.set_metadata('Content-Encoding', 'gzip')
    k.set_metadata('Content-Type', 'text/csv')
    k.set_contents_from_filename(gz.name)

    os.chdir(cwd)
    return bucket.get_key(k.key).generate_url(expires_in=60)
示例#6
0
def write_csv_to_s3(data, is_owner, **kwargs):
    cwd = cd_temp()
    csv_file = csv_file_for(data, **kwargs)
    csv_file.close()
    reader = open(os.path.abspath(csv_file.name), 'r')
    gz = gzip.open(csv_file.name + '.gz', 'wb')
    lines = reader.readlines()
    gz.writelines(lines)
    gz.close()
    reader.close()

    bucket = S3ConnectionFactory.get_export_bucket()
    k = Key(bucket)
    _dir = 'downloads/creator/' if is_owner else 'downloads/reader/'
    k.key = _dir + gz.name
    k.set_metadata('Content-Encoding', 'gzip')
    k.set_metadata('Content-Type', 'text/csv')
    k.set_contents_from_filename(gz.name)

    os.chdir(cwd)
    return bucket.get_key(k.key).generate_url(expires_in=60)