Skip to content

Commit 9962851

Browse files
committed
scripts: syft-license-summary: Fix mix lints
Signed-off-by: Loïc Minier <[email protected]>
1 parent 6f5e22d commit 9962851

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

scripts/syft-license-summary.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,24 @@
77
# format
88

99
import json
10-
import os
1110
import sys
1211
import hashlib
1312
from collections import defaultdict
14-
from pathlib import Path
13+
1514

1615
def load_syft_json(file_path):
1716
with open(file_path, 'r') as f:
1817
return json.load(f)
1918

19+
2020
def sha256_of_file(path):
2121
try:
2222
with open(path, 'rb') as f:
2323
return hashlib.sha256(f.read()).hexdigest()
2424
except Exception:
2525
return "unreadable"
2626

27+
2728
def group_by_source_package(data):
2829
grouped = defaultdict(lambda: {
2930
"binaries": set(),
@@ -36,7 +37,8 @@ def group_by_source_package(data):
3637
metadata = artifact.get("metadata", {})
3738
binary = metadata.get("package", "unknown")
3839
source = metadata.get("source") or binary
39-
source_version = metadata.get("sourceVersion") or metadata.get("version", "")
40+
version = metadata.get("version", "")
41+
source_version = metadata.get("sourceVersion") or version
4042
grouped[source]["binaries"].add(binary)
4143
grouped[source]["source_version"] = source_version
4244

@@ -50,6 +52,7 @@ def group_by_source_package(data):
5052

5153
return grouped
5254

55+
5356
def print_table(grouped):
5457
print("source,version,binaries,licenses,copyright_sha256")
5558
for source, data in grouped.items():
@@ -65,13 +68,13 @@ def print_table(grouped):
6568

6669
print(f"{source},{version},{binaries},{licenses},{hash_summary}")
6770

71+
6872
if __name__ == "__main__":
6973
if len(sys.argv) != 2:
7074
print("Usage: syft-license-summary.py <syft-json-file>")
7175
sys.exit(1)
7276

7377
syft_file = sys.argv[1]
74-
data = load_syft_json(syft_file)
75-
grouped = group_by_source_package(data)
76-
print_table(grouped)
77-
78+
syft_data = load_syft_json(syft_file)
79+
syft_grouped = group_by_source_package(syft_data)
80+
print_table(syft_grouped)

0 commit comments

Comments
 (0)