fix cloc output scrapping. add clone progress and python output to docker logs.

This commit is contained in:
Enzo Nunes
2025-12-05 20:12:55 +00:00
parent 1cac1d2e66
commit 4a4fb621ad
5 changed files with 25 additions and 9 deletions

View File

@@ -1,6 +1,5 @@
import os
import subprocess
import sys
from datetime import datetime, timedelta
import requests
@@ -54,20 +53,28 @@ def get_lines_of_code(owner, repository):
repository_clone_dir = os.path.expanduser(f"{parent_dir}/{repository}")
try:
print(f"Cloning {repository_url}...")
subprocess.run(
["git", "clone", "--depth", "1", repository_url, repository_clone_dir],
["git", "clone", "--depth", "1", "--progress", repository_url, repository_clone_dir],
check=True,
stdout=sys.stdout,
stderr=sys.stderr,
)
print("Clone complete. Running cloc...")
result = subprocess.run(
["cloc", f"--exclude-lang={','.join(EXCLUDED_LANGUAGES)}", repository_clone_dir],
capture_output=True,
text=True,
check=True,
)
number_of_lines_of_code = int(result.stdout.split("\n")[-3].split()[-1])
except Exception:
# Find the SUM line and extract the last column (code lines)
for line in result.stdout.split("\n"):
if line.strip().startswith("SUM:"):
number_of_lines_of_code = int(line.split()[-1])
break
else:
raise ValueError("Could not find SUM line in cloc output")
except Exception as e:
print(f"Error occurred: {e}")
return -1
finally:
subprocess.run(["rm", "-rf", parent_dir], check=True)