s3-mp-cleanup_1.py 745 B

1234567891011121314151617181920
  1. def main(uri, cancel):
  2. # Check that dest is a valid S3 url
  3. split_rs = urlparse.urlsplit(uri)
  4. if split_rs.scheme != "s3":
  5. raise ValueError("'%s' is not an S3 url" % uri)
  6. s3 = boto.connect_s3()
  7. bucket = s3.lookup(split_rs.netloc)
  8. mpul = bucket.list_multipart_uploads()
  9. for mpu in mpul:
  10. if not cancel:
  11. print('s3-mp-cleanup.py s3://{}/{} -c {} # {} {}'.format(mpu.bucket.name, mpu.key_name, mpu.id, mpu.initiator.display_name, mpu.initiated))
  12. elif cancel == mpu.id:
  13. bucket.cancel_multipart_upload(mpu.key_name, mpu.id)
  14. break
  15. else:
  16. if cancel:
  17. print("No multipart upload {} found for {}".format(cancel, uri))
  18. sys.exit(1)