-
-
Notifications
You must be signed in to change notification settings - Fork 17
/
count.py
26 lines (21 loc) · 847 Bytes
/
count.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
from pathlib import Path
from typing import Union, List
def count_lines(directory: Union[str, List[str]]):
"""Count Python LOC in a given directory."""
if isinstance(directory, str):
directories = [directory]
else:
directories = directory
total_lines: int = 0
print("{:>10} |{:>10} | {:<20}".format("ADDED", "TOTAL", "FILE"))
print("{:->11}|{:->11}|{:->20}".format("", "", ""))
for directory in directories:
for path in Path(directory).rglob("*.py"):
with open(path.absolute(), "r") as f:
newlines = f.readlines()
newlines = len(newlines)
total_lines += newlines
print(
"{:>10} |{:>10} | {:<20}".format(newlines, total_lines, str(path))
)
count_lines(["./antispam", "./tests"])