kvisc/ka/mkstats.py

36 lines
756 B
Python
Executable File

#!/usr/bin/python3
import os
from pprint import pprint
instrs = dict()
def mkstat(fp):
for _, line in enumerate(fp):
if len(line) == 0 or line[0] not in ' \t':
continue
tok = line.strip().split()
if len(tok) == 0:
continue
if len(tok[0]) == 0 or tok[0] in ';#@/':
continue
if tok[0] in instrs:
instrs[tok[0]] += 1
else:
instrs[tok[0]] = 1
for root, _, files in os.walk('.'):
for f in files:
if len(f) > 2 and f[-2:] == '.k':
mkstat(open(os.path.join(root, f), "r"))
n = len(instrs.items())
for key, value in sorted(instrs.items(), key=lambda x: x[1]):
print("#{}. {}: {}".format(n, key, value))
n -= 1