Skip to content

Instantly share code, notes, and snippets.

@schlueter
Created June 16, 2015 03:38
Show Gist options
  • Save schlueter/bb0d50df0e5e1a981c08 to your computer and use it in GitHub Desktop.
Save schlueter/bb0d50df0e5e1a981c08 to your computer and use it in GitHub Desktop.
CLI progress output (for Bytes) when partial and total may be queried
import math
def update(partial, total):
measurement_heuristic = int(math.floor(math.log10(total)) - 1)/3
unit, divisor = {
0: ('B', 1),
1: ('kB', 1000),
2: ('MB', 1e6),
3: ('GB', 1e9),
4: ('TB', 1e12)
}[measurement_heuristic]
print("{0:0.2f}{2} of {1:0.2f}{2} downloaded".format(
partial/divisor,
total/divisor,
unit))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment