-
Notifications
You must be signed in to change notification settings - Fork 1
/
sloc.py
90 lines (67 loc) · 2.26 KB
/
sloc.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
87
88
89
90
import os
from os.path import isfile
from sys import argv
if len(argv) > 1:
PATH = argv[1]
else:
PATH = "."
IGNORE = set()
IGNORE_ = ["binpack", "set", "sset", "sets"]
for x in IGNORE_:
IGNORE.add(x.lower())
def count(fpath):
tot = 0
if not (fpath.endswith(".lua") or fpath.endswith(".fnl") or fpath.endswith(".glsl")):
return 0
if fpath==".git":
return 0
with open(fpath, "r") as f:
try:
st = f.read()
for line in st.split("\n"):
if line.replace(" ","").replace("\t",""):
tot += 1
except:
print("Unable to read this path", fpath)
return tot
def count_lines(path):
tot = 0
incl_tot = 0
files = 0
incl_files = 0
for fname in os.listdir(path):
if fname.startswith("."):
# avoiding local git repo!
continue
if fname.startswith("_") or fname.startswith("nm_") or fname.startswith("monkeyp_") or (fname.replace(".lua","").lower() in IGNORE):
# Not my code!
# add to inclusive total.
if isfile(path + "/" + fname):
l = count(path + "/" + fname)
incl_files += 1
else:
_, ll, _, ff = count_lines(path + "/" + fname)
incl_tot += ll
incl_files += ff
continue
if isfile(path + "/" + fname):
lines = count(path + "/" + fname)
tot += lines
incl_tot += lines
files += 1
incl_files += 1
else:
# Its a folder
tot_l, incl_l, f, incl_f = count_lines(path + "/" + fname)
tot += tot_l
incl_tot += incl_l
files += f
incl_files += incl_f
return tot, incl_tot, files, incl_files
TOT, INCLUSIVE, FTOT, FINCLUSIVE = count_lines(PATH)
print("\n"+("="*50))
print("\nYour project has " + str(TOT) + " lines of code that you wrote,")
print("spread across " + str(FTOT) + " of your files.\n")
print("However, there are " + str(INCLUSIVE) + " lines of code total, including other's code.")
print("All the code is spread across " + str(FINCLUSIVE) + " files.")
print("\n" + "="*50)