3 # progress.py - progress meter
5 # Copyright (C) 2003, Xiph.org Foundation
7 # This file is part of positron.
9 # This program is free software; you can redistribute it and/or modify it
10 # under the terms of a BSD-style license (see the COPYING file in the
13 # This program is distributed in the hope that it will be useful, but
14 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY
15 # or FITNESS FOR A PARTICULAR PURPOSE. See the license for more details.
17 from sys
import stderr
21 def sync_start(self
, num_items
):
22 stderr
.write("Downloading %d files...\n" % (num_items
,))
25 def transfer_start(self
, filename
, size
):
28 def transfer_progress(self
, filename
, size
, bytes_so_far
, rate
):
29 self
._print
_line
(filename
, size
, bytes_so_far
, rate
)
31 def transfer_stop(self
, filename
, size
):
32 self
._print
_line
(filename
, size
, size
, 0)
38 def _print_line(self
, filename
, size
, bytes_so_far
, rate
):
39 percent_str
= "%3d%%" % (100 * bytes_so_far
/ size
,)
42 if bytes_so_far
< size
:
43 bar_width
= max_bar_width
* bytes_so_far
/ size
44 bar
= "=" * (bar_width
- 1) + ">"
46 bar
= "=" * max_bar_width
48 size_str
= self
._gen
_size
_str
(size
)
51 rate_str
= self
._gen
_size
_str
(rate
) + "/s"
53 if bytes_so_far
< size
:
54 time_remaining
= (size
- bytes_so_far
) / rate
55 seconds
= time_remaining
% 60
56 minutes
= (time_remaining
// 60) % 60
57 hours
= time_remaining
// 3600
60 eta_str
= "ETA: %d:%02d:%02d" % (hours
, minutes
, seconds
)
62 eta_str
= "ETA: %d:%02d" % (minutes
, seconds
)
69 str = "%-4s|%-*s|%8s %10s %-15s" % (percent_str
, max_bar_width
,
70 bar
, size_str
, rate_str
, eta_str
)
71 str = "\r" + " " * 78 + "\r" + str
74 def _gen_size_str(self
, size
):
79 size_str
= "%dB" % (size
, )
81 size_str
= "%1.1fkB" % (size
/kB
,)
83 size_str
= "%1.1fMB" % (size
/MB
,)
85 size_str
= "%1.1fGB" % (size
/GB
,)