Created
June 16, 2015 03:38
-
-
Save schlueter/bb0d50df0e5e1a981c08 to your computer and use it in GitHub Desktop.
CLI progress output (for Bytes) when partial and total may be queried
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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