equal
deleted
inserted
replaced
39 ''' |
39 ''' |
40 Created on Feb 1, 2012 |
40 Created on Feb 1, 2012 |
41 |
41 |
42 @author: ymh |
42 @author: ymh |
43 ''' |
43 ''' |
44 import sys |
|
45 import codecs #@UnresolvedImport |
44 import codecs #@UnresolvedImport |
46 import math |
45 import math |
|
46 import sys |
47 |
47 |
48 def show_progress(current_line, total_line, label, width, writer=None): |
48 |
|
49 def show_progress(current_line, total_line, label, width, writer=None, newline=False): |
49 |
50 |
50 if writer is None: |
51 if writer is None: |
51 writer = sys.stdout |
52 writer = sys.stdout |
52 if sys.stdout.encoding is not None: |
53 if sys.stdout.encoding is not None: |
53 writer = codecs.getwriter(sys.stdout.encoding)(sys.stdout) |
54 writer = codecs.getwriter(sys.stdout.encoding)(sys.stdout) |
57 marks = math.floor(width * (percent / 100.0)) #@UndefinedVariable |
58 marks = math.floor(width * (percent / 100.0)) #@UndefinedVariable |
58 spaces = math.floor(width - marks) #@UndefinedVariable |
59 spaces = math.floor(width - marks) #@UndefinedVariable |
59 |
60 |
60 loader = u'[' + (u'=' * int(marks)) + (u' ' * int(spaces)) + u']' |
61 loader = u'[' + (u'=' * int(marks)) + (u' ' * int(spaces)) + u']' |
61 |
62 |
62 s = u"%s %3d%% %*d/%d - %*s\r" % (loader, percent, len(str(total_line)), current_line, total_line, width, label[:width]) |
63 s = u"%s %3d%% %*d/%d - %*s%s" % (loader, percent, len(str(total_line)), current_line, total_line, width, label[:width], "\n" if newline else "\r") |
63 |
64 |
64 writer.write(s) #takes the header into account |
65 writer.write(s) #takes the header into account |
65 if percent >= 100: |
66 if percent >= 100: |
66 writer.write("\n") |
67 writer.write("\n") |
67 writer.flush() |
68 writer.flush() |