add script for renaming andmoving files between buckets

This commit is contained in:
Jakub Sokołowski 2018-08-24 14:13:13 -04:00
parent c0dab4eda6
commit 34a0e13c3a
No known key found for this signature in database
GPG Key ID: 4EF064D0E6D63020
1 changed files with 26 additions and 0 deletions

26
s3utils/move_builds.py Normal file
View File

@ -0,0 +1,26 @@
#!/usr/bin/env python3
import os
import boto3
import botocore
BUCKET = 'status-im-desktop'
session = boto3.session.Session()
s3 = session.client('s3',
region_name='ams3',
endpoint_url='https://ams3.digitaloceanspaces.com',
aws_access_key_id=os.environ['DO_ID'],
aws_secret_access_key=os.environ['DO_SECRET'])
for f in s3.list_objects_v2(Bucket=BUCKET)['Contents']:
name = f['Key']
when = f['LastModified']
new_name = 'StatusIm.{}.{}.nightly.{}'.format(
when.strftime('%y%m%d.%H%M%S'),
name[9:15],
name.split('.')[-1]
)
print('{:<25} -> {}'.format(name, new_name))
path = '/tmp/{}'.format(new_name)
#s3.download_file(BUCKET, name, path)
#s3.upload_file(path, BUCKET, new_name)