--- /dev/null
+"Broytman Flat ASCII Database for Python, Copyright (C) 1996-2001 PhiloSoft Design"
--- /dev/null
+"Broytman Flat ASCII Database for Python - Test, Copyright (C) 1996-2001 PhiloSoft Design"
--- /dev/null
+#! /usr/bin/env python
+
+
+import sys
+from time import sleep
+from m_lib.pbar.tty_pbar import ttyProgressBar
+
+def test():
+ print "Test: ",
+ sys.stdout.flush()
+
+ x1 = 217
+ x2 = 837
+
+ pbar = ttyProgressBar(x1, x2)
+ for i in range(x1, x2+1):
+ pbar.display(i)
+ sleep(0.05)
+
+ pbar.erase()
+ print "Ok"
+
+
+if __name__ == "__main__":
+ test()
--- /dev/null
+#! /usr/bin/env python
+"""
+ Test N1 to time file reading
+"""
+
+import sys
+from clock import clock
+
+
+def test():
+ print "Test: ",
+ sys.stdout.flush()
+
+ infile = open(sys.argv[1])
+ lines = infile.readlines()
+ infile.close()
+
+ print "Ok"
+
+
+if __name__ == "__main__":
+ test()
+ print "Overall time:", clock()
--- /dev/null
+#! /usr/bin/env python
+"""
+ Test N2 to time file reading
+"""
+
+import sys
+from clock import clock
+
+
+def test():
+ print "Test: ",
+ sys.stdout.flush()
+
+ infile = open(sys.argv[1])
+ lines = []
+ line = '\n'
+ while line:
+ line = infile.readline()
+ lines.append(line)
+ infile.close()
+
+ print "Ok"
+
+
+if __name__ == "__main__":
+ test()
+ print "Overall time:", clock()
--- /dev/null
+#! /usr/bin/env python
+"""
+ Test N3 to time file reading
+"""
+
+import sys, os
+from clock import clock
+from m_lib.pbar.tty_pbar import ttyProgressBar
+
+
+def test():
+ print "Test: ",
+ sys.stdout.flush()
+
+ size = os.path.getsize(sys.argv[1])
+ infile = open(sys.argv[1])
+ pbar = ttyProgressBar(0, size)
+
+ lines = []
+ line = '\n'
+ lng = 0
+
+ # This is for DOS - it counts CRLF, which len() counts as 1 char!
+ if os.name == 'dos' or os.name == 'nt' :
+ dos_add = 1
+ else:
+ dos_add = 0 # UNIX' and Mac's len() counts CR or LF correct
+
+ while line:
+ line = infile.readline()
+ lines.append(line)
+
+ lng = lng + len(line) + dos_add
+ pbar.display(lng)
+
+ infile.close()
+ pbar.erase()
+
+ print "Ok"
+
+
+if __name__ == "__main__":
+ test()
+ print "Overall time:", clock()
--- /dev/null
+#! /usr/bin/env python
+"""
+ Test N4: earse()/redraw()
+"""
+
+import sys
+from time import sleep
+from m_lib.pbar.tty_pbar import ttyProgressBar
+
+
+def test():
+ sys.stdout.write("Displaying... ")
+ sys.stdout.flush()
+
+ pbar = ttyProgressBar(0, 100)
+ pbar.display(42)
+ sleep(2)
+ pbar.erase()
+
+ sys.stdout.write("erasing... ")
+ sys.stdout.flush()
+ sleep(2)
+
+ sys.stdout.write("redisplaying... ")
+ sys.stdout.flush()
+ pbar.redraw()
+ sleep(2)
+
+ del pbar
+ print "Ok"
+
+
+if __name__ == "__main__":
+ test()
--- /dev/null
+"""
+ Progress bar (TTY version)
+
+ Written by Broytman, Jan 1997 - Sep 2003. Copyright (C) 1997-2003 PhiloSoft Design
+"""
+
+
+import sys, os
+
+
+class ttyProgressBar:
+ """
+ Simple progress indicator - displays bar "graph" using standard tty
+ commands - space, backspace, etc. This method is compatible with
+ (almost) all UNIX consoles and DOS boxes.
+
+ Example:
+
+ ====------ 42%
+
+ This is a "bar" (width 10 chars) for 42%
+
+ Certainly, to use it nicely, do not write anything on screen
+ (to stdout or stderr), while using it (or use erase()/redraw() methods).
+ Erase or delete it after using.
+ """
+
+ left_c = '#' # Chars for "graphics"
+ right_c = '_'
+ space_c = ' ' # a space
+ back_c = chr(8) # a backspace
+
+ if os.name == 'dos' or os.name == 'nt' : # Use nice chars on DOS screen
+ left_c = chr(178)
+ right_c = chr(176)
+
+
+ def __init__(self, min, max, out = sys.stderr, width1 = 10,
+ width2 = 1+3+1): # 1 space + 3 chars for "100" + 1 for "%"
+ self.min = min
+ self.current = min
+ self.max = max - min
+
+ self.width1 = width1
+ self.width2 = width2
+ self.out = out
+
+ self.redraw()
+
+
+ def __del__(self):
+ self.erase()
+
+
+ def display(self, current):
+ """
+ Draw current value on indicator.
+ Optimized to draw as little as possible.
+ """
+
+ self.current = current
+ current -= self.min
+ lng = (current * self.width1) / self.max
+
+ if current >= self.max:
+ percent = 100
+ else:
+ percent = (current * 100) / self.max
+
+ flush = False
+
+ if self.lng <> lng:
+ self.lng = lng
+ self.out.write(ttyProgressBar.back_c*(self.width1+self.width2))
+ self.out.write(ttyProgressBar.left_c*lng)
+ self.out.write(ttyProgressBar.right_c*(self.width1-lng) + ttyProgressBar.space_c)
+ self.percent = -1 # force to redraw percentage; the bug was fixed by William McVey
+ flush = True
+
+ elif self.percent <> percent:
+ self.out.write(ttyProgressBar.back_c * (self.width2-1))
+ flush = True
+
+
+ if self.percent <> percent:
+ self.percent = percent
+ self.out.write(str(percent).rjust(3) + '%')
+ flush = True
+
+
+ if flush:
+ self.out.flush()
+
+ self.visible = True
+
+
+ def erase(self):
+ if self.visible: # Prevent erase() to be called twice - explicitly and from __del__()
+ self.out.write(ttyProgressBar.back_c*(self.width1+self.width2))
+ self.out.write(ttyProgressBar.space_c*(self.width1+self.width2))
+ self.out.write(ttyProgressBar.back_c*(self.width1+self.width2))
+ self.out.flush()
+ self.visible = False
+
+
+ def redraw(self):
+ self.lng = -1 # force to draw bar on the first call
+ self.percent = -1
+
+ # Clear space - just in case there was some cruft left
+ self.out.write(ttyProgressBar.space_c*(self.width1+self.width2))
+ # redraw everything
+ self.display(self.current)
platforms = "All",
packages = ["m_lib", "m_lib.clock", "m_lib.flad", "m_lib.flad.test",
"m_lib.hash", "m_lib.hash.test", "m_lib.lazy",
- "m_lib.net", "m_lib.net.ftp", "m_lib.net.www", "m_lib.rus",
- ],
+ "m_lib.net", "m_lib.net.ftp", "m_lib.net.www",
+ "m_lib.pbar", "m_lib.pbar.test", "m_lib.rus",
+ ],
data_files = [("%s/m_lib/flad/test" % python_lib, [
"m_lib/flad/test/test.cfg",
"m_lib/flad/test/test.txt",