47
47
def clear_progress_bar():
48
48
sys.stderr.write('\r%s\r' % (' '*79))
50
def spinner_str(progress, show_text=False):
52
Produces the string for a textual "spinner" progress indicator
53
:param progress: an object represinting current progress
54
:param show_text: If true, show progress text as well
55
:return: The spinner string
57
>>> spinner_str(Progress("baloons", 0))
59
>>> spinner_str(Progress("baloons", 5))
61
>>> spinner_str(Progress("baloons", 6), show_text=True)
64
positions = ('|', '/', '-', '\\')
65
text = positions[progress.current % 4]
67
text+=" %i %s" % (progress.current, progress.units)
70
def spinner(progress, show_text=False, output=sys.stderr):
72
Update a spinner progress indicator on an output
73
:param progress: The progress to display
74
:param show_text: If true, show text as well as spinner
75
:param output: The output to write to
77
>>> spinner(Progress("baloons", 6), show_text=True, output=sys.stdout)
80
output.write('\r%s' % spinner_str(progress, show_text))
84
result = doctest.testmod()
87
print "All tests passed"
89
print "No tests to run"
90
if __name__ == "__main__":