-
Notifications
You must be signed in to change notification settings - Fork 0
/
find_bitrot_code.py
executable file
·62 lines (51 loc) · 1.71 KB
/
find_bitrot_code.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
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
from os.path import basename
threshold = 5
total_matches = 0
#===============================================================================
def main():
if(len(sys.argv) < 2):
print("Tool for finding large commented regions of code. Uses very simply heuristics.")
print("Usage: find_bitrot_code <file1.F> ... <fileN.F>")
sys.exit(1)
files = sys.argv[1:]
for fn in files:
check(fn)
print("Found %d spots in %d files."%(total_matches, len(files)))
#===============================================================================
def check(fn):
f = open(fn)
all_lines = f.read().split("\n")
counter = 0
start = 0
def report():
global total_matches
total_matches += 1
print(" +"+("-"*87)+"+")
msg = "%s: line %d ... line %d"%(basename(fn), start+1, lineno+1)
print(" | "+msg.ljust(85) +" |")
print(" +"+("-"*87)+"+")
for i in range(start, lineno):
print(" | %4d "%(i)+all_lines[i].ljust(80) +" |")
print(" +"+("-"*87)+"+")
print("\n")
for lineno, line in enumerate(all_lines):
s = line.strip().lower()
if(s.startswith("!>") or s.startswith("!$omp")):
if(counter > threshold): report()
counter = 0
elif(s.startswith("!")):
if(counter==0):
start=lineno
counter += 1
elif(len(s) > 0):
if(counter > threshold): report()
counter = 0
#===============================================================================
if(len(sys.argv)==2 and sys.argv[-1]=="--selftest"):
pass #TODO implement selftest
else:
main()
#EOF