-
Notifications
You must be signed in to change notification settings - Fork 6
/
stat_gen.py
80 lines (59 loc) · 1.57 KB
/
stat_gen.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import os
base_path = os.getcwd()
py_count = 0
idl_count = 0
h_count = 0
py_line_count = 0
idl_line_count = 0
h_line_count = 0
def iter_folder(path):
global py_count
global idl_count
global h_count
global py_line_count
global idl_line_count
global h_line_count
files = list(
os.path.join(path, f) for f in os.listdir(path)
if '__init__' not in f
)
for f in files:
if f.endswith('.h'):
h_count += 1
with open(f, 'r') as fle:
h_line_count += len(fle.readlines())
elif f.endswith('.idl'):
idl_count += 1
with open(f, 'r') as fle:
idl_line_count += len(fle.readlines())
elif f.endswith('.py'):
py_count += 1
with open(f, 'r') as fle:
py_line_count += len(fle.readlines())
elif os.path.isdir(f):
iter_folder(f)
shared = os.path.join(base_path, 'shared')
km = os.path.join(base_path, 'km')
um = os.path.join(base_path, 'um')
ucrt = os.path.join(base_path, 'ucrt')
iter_folder(shared)
iter_folder(km)
iter_folder(um)
iter_folder(ucrt)
template = '''\
current statistics
total number of C code files {0}
number of files converted {1}
total number of C code lines {2}
number of line converted {3}
percentage of files completed: {4:.2f} %
percentage of line of code converted {5:.2f} %
'''
print template.format(
h_count,
py_count,
h_line_count,
py_line_count,
(float(py_count) / float(h_count)) * 100.0,
(float(py_line_count) / float(h_line_count)) * 100.0
)