Last active
December 27, 2015 17:29
-
-
Save JohannesBuchner/7362815 to your computer and use it in GitHub Desktop.
ETA from external programs
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
"""Estimate Time until completion of a process. | |
Usage: <statusprog> | howlong.py <n> | |
<statusprog> is a program that writes a line to stdout from time to time. | |
The line is the number of items completed so far. | |
<n> is the total number of items to complete. | |
Example: | |
for((i=0;i<20;i++)); do echo $i; sleep 1; done | python howlong.py 20 | |
Author: Johannes Buchner (C) 2013 | |
""" | |
import sys | |
import progressbar | |
if len(sys.argv) < 2: | |
sys.stderr.write(__doc__) | |
sys.exit(-1) | |
n = int(sys.argv[1]) | |
k = int(sys.stdin.readline()) | |
m = n - k | |
print 'starting with {} of {} done. {} left'.format(k, n, m) | |
if m > 0: | |
pbar = progressbar.ProgressBar( | |
widgets=[progressbar.Percentage(), progressbar.Counter('%5d'), | |
progressbar.Bar(), progressbar.ETA()], | |
maxval=m).start() | |
while True: | |
l = sys.stdin.readline() | |
if l == '': break | |
l = int(l) | |
pbar.update(l - k) | |
if l == m: | |
break | |
pbar.finish() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment