|
0
|
1 |
# -*- coding: utf-8 -*- |
|
|
2 |
''' |
|
|
3 |
Created on Feb 1, 2012 |
|
|
4 |
|
|
|
5 |
@author: ymh |
|
|
6 |
''' |
|
|
7 |
import sys |
|
|
8 |
import codecs #@UnresolvedImport |
|
|
9 |
import math |
|
|
10 |
|
|
|
11 |
def show_progress(current_line, total_line, label, width, writer=None): |
|
|
12 |
|
|
|
13 |
if writer is None: |
|
|
14 |
writer = sys.stdout |
|
|
15 |
if sys.stdout.encoding is not None: |
|
|
16 |
writer = codecs.getwriter(sys.stdout.encoding)(sys.stdout) |
|
|
17 |
|
|
|
18 |
percent = (float(current_line) / float(total_line)) * 100.0 |
|
|
19 |
|
|
|
20 |
marks = math.floor(width * (percent / 100.0)) #@UndefinedVariable |
|
|
21 |
spaces = math.floor(width - marks) #@UndefinedVariable |
|
|
22 |
|
|
|
23 |
loader = u'[' + (u'=' * int(marks)) + (u' ' * int(spaces)) + u']' |
|
|
24 |
|
|
|
25 |
s = u"%s %3d%% %*d/%d - %*s\r" % (loader, percent, len(str(total_line)), current_line, total_line, width, label[:width]) |
|
|
26 |
|
|
|
27 |
writer.write(s) #takes the header into account |
|
|
28 |
if percent >= 100: |
|
|
29 |
writer.write("\n") |
|
|
30 |
writer.flush() |
|
|
31 |
|
|
|
32 |
return writer |