add script for renaming builds

This commit is contained in:
Jakub Sokołowski 2018-08-30 13:40:38 -04:00
parent 4d94401d65
commit 81a59dd20a
No known key found for this signature in database
GPG Key ID: 4EF064D0E6D63020
1 changed files with 25 additions and 0 deletions

25
s3utils/rename_builds.py Normal file
View File

@ -0,0 +1,25 @@
#!/usr/bin/env python3
import os
import boto3
import botocore
BUCKET = 'status-im'
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']
if name.startswith('StatusIm-') or name == 'index.html':
continue
# exception for last dot before file extension
dots = name.count('.')
new_name = name.replace('.', '-', dots-1)
print('{:<30} -> {}'.format(name, new_name))
s3.copy({'Bucket': BUCKET, 'Key': name}, BUCKET, new_name)
s3.delete_object(Bucket=BUCKET, Key=name)