34 lines
1.0 KiB
Python
34 lines
1.0 KiB
Python
from pathlib import Path
|
|
|
|
from app.modules.impl_tracker.domain.entities import CodeStructure
|
|
from app.modules.scanner.domain.entities import ScanResult
|
|
|
|
|
|
def scan_code_directory(code_dir: str, scan_result: ScanResult) -> CodeStructure:
|
|
root = Path(code_dir)
|
|
if not root.is_dir():
|
|
return CodeStructure(root_path=code_dir, directories=[], files=[], matched_modules=[])
|
|
|
|
directories = []
|
|
files = []
|
|
for p in sorted(root.rglob("*")):
|
|
rel = str(p.relative_to(root))
|
|
if p.is_dir():
|
|
directories.append(rel)
|
|
elif p.is_file():
|
|
files.append(rel)
|
|
|
|
# Match modules by checking if code_root from CodebaseAlignment exists
|
|
matched = []
|
|
for alignment in scan_result.codebase_alignments:
|
|
code_root = alignment.code_root
|
|
if (root / code_root).exists():
|
|
matched.append(alignment.module_id)
|
|
|
|
return CodeStructure(
|
|
root_path=code_dir,
|
|
directories=directories,
|
|
files=files,
|
|
matched_modules=matched,
|
|
)
|