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