top_evil_rs.py: use glob to walk into subdirs

Otherwise configure/* is not included in the report.
This commit is contained in:
Alexander Krotov
2019-08-25 21:40:30 +03:00
committed by Floris Bruynooghe
parent f13b068479
commit ae17971599

View File

@@ -1,24 +1,24 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
from pathlib import Path
import os import os
import re import re
if __name__ == "__main__": if __name__ == "__main__":
filestats = [] filestats = []
for fn in os.listdir(): for fn in Path(".").glob("**/*.rs"):
if fn.endswith(".rs"): s = fn.read_text()
s = open(fn).read() s = re.sub(r"(?m)///.*$", "", s) # remove comments
s = re.sub(r'(?m)///.*$', '', s) # remove comments unsafe = s.count("unsafe")
unsafe = s.count("unsafe") free = s.count("free(")
free = s.count("free(") gotoblocks = s.count("current_block =")
gotoblocks = s.count("current_block =") filestats.append((fn, unsafe, free, gotoblocks))
filestats.append((fn, unsafe, free, gotoblocks))
sum_unsafe, sum_free, sum_gotoblocks = 0, 0, 0 sum_unsafe, sum_free, sum_gotoblocks = 0, 0, 0
for fn, unsafe, free, gotoblocks in reversed(sorted(filestats, key=lambda x: sum(x[1:]))): for fn, unsafe, free, gotoblocks in reversed(sorted(filestats, key=lambda x: sum(x[1:]))):
print("{0: <30} unsafe: {1: >3} free: {2: >3} goto-blocks: {3: >3}".format(fn, unsafe, free, gotoblocks)) print("{0: <30} unsafe: {1: >3} free: {2: >3} goto-blocks: {3: >3}".format(str(fn), unsafe, free, gotoblocks))
sum_unsafe += unsafe sum_unsafe += unsafe
sum_free += free sum_free += free
sum_gotoblocks += gotoblocks sum_gotoblocks += gotoblocks