-
Notifications
You must be signed in to change notification settings - Fork 1
/
rst-stats.py
executable file
·53 lines (40 loc) · 1.22 KB
/
rst-stats.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
#!/usr/bin/env python3
import os
from pathlib import Path
from termcolor import colored
def get_color_by_loc(loc):
if loc < 100:
return 'red'
elif loc > 1000:
return 'cyan'
else:
return 'white'
totalloc = 0
alllocs = []
filelist = []
folders = {}
for root, _, files in os.walk('.'):
for file in files:
if file.endswith(('.rst', '.md')):
full = Path(root, file)
filelist.append(full)
folders[full.parent] = 0
filelist = sorted(filelist)
filecount = len(filelist)
for file in filelist:
loc = len(open(file).read().splitlines())
totalloc += loc
alllocs.append(loc)
for f in folders.keys():
if file.is_relative_to(f):
folders[f] += loc
folder = str(file.parent) + '/'
name = file.name
print(f'{colored(folder, "magenta")}{colored(name, "green")} [{colored(loc, get_color_by_loc(loc))}]')
print(f'\n=== TOTAL files: {filecount}')
print(f'Total LOC: {totalloc}')
print(f'Average LOC: {totalloc // filecount}')
print(f'Median LOC: {alllocs[len(alllocs) // 2]}')
print('\n=== FOLDERS ===')
for folder, count in sorted(folders.items(), key=lambda x: x[0]):
print(f'{colored(folder, "magenta")}: {count}')