-
Notifications
You must be signed in to change notification settings - Fork 0
/
Expansion_a.py
86 lines (76 loc) · 2.39 KB
/
Expansion_a.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
81
82
83
84
85
86
import re
def get_special_num(file, aim = None):
get_empty_line(file, aim)
get_annotate_line(file, aim)
get_code_line(file, aim)
def get_empty_line(file, aim = None):
empty_line = 0
try:
with open(file) as f:
for line in f:
if (len(line.strip()) <= 1) and re.search('{|}',line.strip()):
empty_line += 1
except:
pass
stre = ('empty:',empty_line, '\n')
print('empty:',empty_line)
if aim:
aim.insert('insert', stre)
return empty_line
def get_code_line(file, aim = None):
code_line = 0
try:
with open(file) as f:
for line in f:
if (len(line.strip()) > 1) and not re.search('//',line.strip()):
code_line += 1
except:
pass
code_line -= get_block_annotate_line(file, aim = None)
strc = ('code:',code_line ,'\n')
print('code:',code_line )
if aim:
aim.insert('insert', strc)
return code_line
def get_annotate_line(file, aim = None):
annotate_line = 0
try:
with open(file) as f:
for line in f:
if re.search('//', line.strip()):
annotate_line += 1
f.close()
with open(file) as f:
is_annotate = False
try:
for line in f:
if re.search('/\*', line.strip()):
is_annotate = True
if is_annotate == True:
annotate_line += 1
if re.search('\*/', line.strip()):
is_annotate = False
except:
print('err')
except:
pass
stra = ('annotate:',annotate_line,'\n')
print('annotate:',annotate_line)
if aim:
aim.insert('insert', stra)
return annotate_line
def get_block_annotate_line(file, aim = None):
block_annotate_line = 0
with open(file) as f:
is_annotate = False
for line in f:
if re.search('/\*', line.strip()):
is_annotate = True
if is_annotate == True:
block_annotate_line += 1
if re.search('\*/', line.strip()):
is_annotate = False
return block_annotate_line
if __name__ == '__main__':
path = 'D:\BianChenRuanJian\PyCharm\PyCharm Community Edition 2017.3.4\WordCounter\\testfile\\test3.c'
get_special_num(path)