Skip to content

Instantly share code, notes, and snippets.

@clayg
Created April 12, 2016 18:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save clayg/2458a4a7e1451c75fbc5a63fcae11635 to your computer and use it in GitHub Desktop.
Save clayg/2458a4a7e1451c75fbc5a63fcae11635 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import sys
import time
from argparse import ArgumentParser
from swiftclient.client import (get_auth, get_object)
auth = 'http://127.0.0.1:8080/auth/v1.0'
user = 'test:tester'
key = 'testing'
slowness = 0.5
parser = ArgumentParser()
parser.add_argument('-S', '--slowness', default=slowness, type=float,
help='How much sleep between chunks')
parser.add_argument('cont_name', help='cont_name')
parser.add_argument('obj_name', help='obj_name')
def main():
options = parser.parse_args()
url, token = get_auth(auth, user, key)
headers, body = get_object(url, token, options.cont_name, options.obj_name,
resp_chunk_size=65000)
total = headers.get('content-length')
next_status = time.time() + 1
downloaded = 0
for chunk in body:
downloaded += len(chunk)
time.sleep(options.slowness)
if time.time() >= next_status:
next_status = time.time() + 1
print '%s/%s' % (downloaded, total)
print '%s/%s' % (downloaded, total)
if __name__ == "__main__":
sys.exit(main())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment