Last active
August 29, 2015 14:23
-
-
Save JohannesBuchner/11e6d213eb879124087a to your computer and use it in GitHub Desktop.
Console progress bar -- takes stdin from arbitrary commands and plots a progress bar
This file contains 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
""" | |
SYNOPSIS: ./myprog | python console-progress.py | |
example for myprog: | |
#!/bin/bash | |
echo 100 | |
for i in $(seq 1 100) | |
do | |
sleep 1 | |
echo $i | |
done | |
""" | |
import progressbar | |
import sys | |
end = sys.stdin.readline() | |
pbar = progressbar.ProgressBar( | |
widgets=[progressbar.Percentage(), progressbar.Counter('%5d'), progressbar.Bar(), progressbar.ETA()], | |
maxval=float(end)).start() | |
while True: | |
current = sys.stdin.readline() | |
if current is None: | |
break | |
pbar.update(float(current)) | |
pbar.finish() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment