def process_bar(self, done, block, total, mode=1):
"""
Draw `Process Bar` at the bottom which is used to indicate progress of
downloading operation.
.. note:: This method is a callback function responses to
:meth:`urllib.urlretrieve` method while fetching hosts data
file.
:param done: Block count of packaged retrieved.
:type done: int
:param block: Block size of the data pack retrieved.
:type block: int
:param total: Total size of the hosts data file.
:type total: int
:param mode: A flag indicating the status of `Process Bar`.
The default value of `mode` is `1`.
==== ====================================
mode `Process Bar` status
==== ====================================
1 Downloading operation is processing.
0 Not downloading.
==== ====================================
:type mode: int
"""
screen = self._stdscr.subwin(2, 80, 20, 0)
screen.bkgd(' ', curses.color_pair(4))
normal = curses.A_NORMAL
line_width = 76
prog_len = line_width - 20
# Progress Bar
if mode:
done *= block
prog = 1.0 * prog_len * done / total
progress = ''.join(['=' * int(prog), '-' * int(2 * prog % 2)])
progress = progress.ljust(prog_len)
total = CommonUtil.convert_size(total).ljust(7)
done = CommonUtil.convert_size(done).rjust(7)
else:
progress = ' ' * prog_len
done = total = 'N/A'.center(7)
# Show Progress
prog_bar = "[%s] %s | %s" % (progress, done, total)
screen.addstr(1, 2, prog_bar, normal)
screen.refresh()
评论列表
文章目录