-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathprogress.py
More file actions
42 lines (34 loc) · 1.06 KB
/
progress.py
File metadata and controls
42 lines (34 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import time, sys
def print_no_nl(s):
sys.stderr.write(str(s))
sys.stderr.flush()
def line_erase():
print_no_nl("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b")
def draw_progress(curr_x, max_x, start_time):
curr_time = time.time()
p = int(1000.0*curr_x/max_x)/10;
n = int(p/5)
es = -1
if curr_x > max_x:
curr_x = max_x
if curr_x > 0:
if curr_x == max_x:
# total time taken
es = int(curr_time-start_time)
else:
# estimated time remaining
es = int((curr_time-start_time) * ((max_x-curr_x)/curr_x))
es_str = ""
if es > 0:
if es > 7200:
es_str = str(int(es/3600)) + "hr."
elif es > 120:
es_str = str(int(es/60)) + "min."
else:
es_str = str(int(es)) + "sec."
line_erase()
print_no_nl('[' + '*'*n + '.'*(20-n) + "] " + str(int(curr_x)) + '/' + str(int(max_x)) + " " + str(round(p,1)) + "% " + es_str + " ")
def erase_progress():
line_erase()
print_no_nl(" " * 79)
line_erase()