in atr/tasks/checks/zipformat.py [0:0]
def _license_headers_check_core_logic_zip(artifact_path: str) -> dict[str, Any]:
"""Verify license headers for files within a zip archive."""
files_checked = 0
files_with_issues: list[str] = []
try:
with zipfile.ZipFile(artifact_path, "r") as zf:
members = zf.infolist()
for member_info in members:
if member_info.is_dir():
continue
member_path = member_info.filename
_, extension = os.path.splitext(member_path)
extension = extension.lower().lstrip(".")
if not _license_headers_check_should_check_zip(member_path, extension):
continue
files_checked += 1
is_valid, error_msg = _license_headers_check_single_file_zip(zf, member_info, extension)
if error_msg:
# Already includes path and error type
files_with_issues.append(error_msg)
elif not is_valid:
# Just append path for header mismatch
files_with_issues.append(member_path)
if files_with_issues:
return {
"valid": False,
"files_checked": files_checked,
"files_without_headers": files_with_issues,
"error_message": None,
}
else:
return {
"valid": True,
"files_checked": files_checked,
"files_without_headers": [],
"error_message": None,
}
except zipfile.BadZipFile as e:
return {"valid": False, "error_message": f"Bad zip file: {e}"}
except FileNotFoundError:
return {"valid": False, "error_message": "File not found"}
except Exception as e:
return {"valid": False, "error_message": f"Unexpected error: {e}"}