forked from smythi93/Tests4Py
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cloc.py
65 lines (58 loc) · 1.72 KB
/
cloc.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
import os
import subprocess
import tests4py.api as t4p
from tests4py.projects import Project
def loc(project: Project):
project.buggy = True
report = t4p.checkout(project)
if report.raised:
raise RuntimeError(
f"bug: checkout of {project.get_identifier()}", report.raised
)
cloc = (
["cloc", "--include-lang=Python"]
+ (
[
"--fullpath",
"--not-match-d="
+ "|".join(
[os.path.join(report.location, s) for s in project.excluded_files]
),
]
if project.excluded_files
else []
)
+ [os.path.join(report.location, s) for s in project.source_base]
)
lines = subprocess.run(
cloc,
stdout=subprocess.PIPE,
)
if lines.returncode != 0:
raise RuntimeError(f"bug: cloc of {project.get_identifier()}")
if b"SUM" not in lines.stdout:
project.loc = int(
lines.stdout.split(b"Python")[1].split(b"\n")[0].split(b" ")[-1].strip()
)
else:
project.loc = int(
lines.stdout.split(b"SUM")[1].split(b"\n")[0].split(b" ")[-1].strip()
)
return project
def main():
projects = list()
t4p.logging.error()
for project in t4p.get_projects():
project.buggy = True
try:
project = loc(project)
except:
pass
else:
projects.append(project)
print(f"{project.get_identifier():<40}: {project.loc:>10}")
with open("cloc.txt", "w") as fp:
for project in projects:
fp.write(f"{project.get_identifier():<40}: {project.loc:>10}\n")
if __name__ == "__main__":
main()