Skip to content

Instantly share code, notes, and snippets.

@JohannesBuchner JohannesBuchner/howlong.py
Last active Dec 27, 2015

Embed
What would you like to do?
ETA from external programs
"""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
You can’t perform that action at this time.