]> git.phdru.name Git - m_lib.git/blob - m_lib/pbar/test/test3.py
84a56c36a99c4e45a8d9707f7e881d593e7211dc
[m_lib.git] / m_lib / pbar / test / test3.py
1 #! /usr/bin/env python
2 """
3    Test N3 to time file reading
4 """
5
6 import sys, os
7 from clock import clock
8 from m_lib.pbar.tty_pbar import ttyProgressBar
9
10
11 def test():
12    print "Test: ",
13    sys.stdout.flush()
14
15    size = os.path.getsize(sys.argv[1])
16    infile = open(sys.argv[1])
17    pbar = ttyProgressBar(0, size)
18
19    lines = []
20    line = '\n'
21    lng = 0
22
23    # This is for DOS - it counts CRLF, which len() counts as 1 char!
24    if os.name == 'dos' or os.name == 'nt' :
25       dos_add = 1
26    else:
27       dos_add = 0 # UNIX' and Mac's len() counts CR or LF correct
28
29    while line:
30       line = infile.readline()
31       lines.append(line)
32
33       lng = lng + len(line) + dos_add
34       pbar.display(lng)
35
36    infile.close()
37    pbar.erase()
38
39    print "Ok"
40
41
42 if __name__ == "__main__":
43    test()
44    print "Overall time:", clock()