Skip to content

Commit d2ceeda

Browse files
committed
Unignore sloc.py
1 parent 1be13b4 commit d2ceeda

File tree

2 files changed

+50
-1
lines changed

2 files changed

+50
-1
lines changed

.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,4 @@
1616

1717
# reignore files
1818
*.DS_Store
19-
*.py
2019
progress.roc

sloc.py

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#!/usr/bin/env python3
2+
# filepath: count_roc_lines.py
3+
4+
import os
5+
import sys
6+
from pathlib import Path
7+
8+
def count_lines_in_file(file_path):
9+
"""Count the number of lines in a file."""
10+
try:
11+
with open(file_path, 'r', encoding='utf-8') as file:
12+
return len(file.readlines())
13+
except Exception as e:
14+
print(f"Error reading {file_path}: {e}", file=sys.stderr)
15+
return 0
16+
17+
def main():
18+
current_dir = Path('.')
19+
roc_files = list(current_dir.glob('**/*.roc'))
20+
21+
if not roc_files:
22+
print("No .roc files found in the current directory or subdirectories.")
23+
return
24+
25+
total_lines = 0
26+
results = []
27+
28+
for file_path in roc_files:
29+
line_count = count_lines_in_file(file_path)
30+
total_lines += line_count
31+
results.append((str(file_path), line_count))
32+
33+
# Sort by line count (descending)
34+
results.sort(key=lambda x: x[1], reverse=True)
35+
36+
# Print results in a table format
37+
print("\nLines of code in .roc files:")
38+
print("-" * 60)
39+
print(f"{'File':<45} | {'Lines':<10}")
40+
print("-" * 60)
41+
42+
for file_path, line_count in results:
43+
print(f"{file_path:<45} | {line_count:<10}")
44+
45+
print("-" * 60)
46+
print(f"{'Total':<45} | {total_lines:<10}")
47+
print(f"\nFound {len(roc_files)} .roc files with a total of {total_lines} lines")
48+
49+
if __name__ == "__main__":
50+
main()

0 commit comments

Comments
 (0)