Skip to content

Instantly share code, notes, and snippets.

@apg
Created November 18, 2011 22:27
Show Gist options
  • Save apg/1377971 to your computer and use it in GitHub Desktop.
Save apg/1377971 to your computer and use it in GitHub Desktop.
I wrote a great upload callback for boto S3 stuff
import itertools, sys
SPINNER = itertools.cycle(['-', '/', '|', '\\'])
def upload_callback(bytes_sent, bytes_total):
cols = 67
if bytes_total > 0:
percent = bytes_sent / float(bytes_total)
else:
percent = 0
numbar = int(cols * percent)
sys.stdout.write("\n\x1b[1A\x1b[2K" + "[%-67s %s % 3d%%]" % \
('=' * numbar, SPINNER.next(), int(percent * 100)))
# you can test it like so too:
import time
i = 1
while i < 100:
upload_callback(i, 100)
i += 1
time.sleep(0.05)
upload_callback(100, 100)
print
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment