Skip to content

Commit b264859

Browse files
author
Glenn Snyder
committed
adding file level license and copyright output
1 parent c807197 commit b264859

File tree

1 file changed

+42
-6
lines changed

1 file changed

+42
-6
lines changed

examples/convert_bom_component_origin_info_to_csv.py

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,15 @@
2525
with open(args.output_file, 'w') as csv_file:
2626
columns = [
2727
'component',
28-
'component modified',
2928
'file path',
3029
'file name',
3130
'archive context',
3231
'usage(s)',
3332
'license(s)',
34-
'match type(s)',
35-
'scan (code location)'
33+
'source',
34+
'origin(s)',
35+
'origin_id(s)',
36+
'copyright'
3637
]
3738
writer = csv.DictWriter(csv_file, fieldnames=columns)
3839
writer.writeheader()
@@ -45,17 +46,52 @@
4546
for matched_file_info in component_info.get('matched_files', []):
4647
row = {
4748
'component': component,
48-
'component modified': component_info['bom_component_info'].get('componentModified', None),
4949
'file path': matched_file_info['filePath']['path'],
5050
'file name': matched_file_info['filePath']['fileName'],
5151
'archive context': matched_file_info['filePath']['archiveContext'],
5252
'usage(s)': ",".join(matched_file_info['usages']),
5353
'license(s)': ",".join([l['licenseDisplay'] for l in component_info['bom_component_info']['licenses']]),
54-
'match type(s)': ",".join(component_info['bom_component_info']['matchTypes']),
55-
'scan (code location)': matched_file_info.get('scan', {}).get('name', 'unknown')
54+
'source': 'customers source',
55+
'origin(s)': ",".join([o['externalNamespace'] for o in component_info['bom_component_info']['origins']]),
56+
'origin_id(s)': ",".join([o.get('externalId', "") for o in component_info['bom_component_info']['origins']]),
57+
'copyright': None,
5658
}
5759
writer.writerow(row)
5860

61+
for origin in component_info.get('all_origin_details', []):
62+
for license in origin.get('file_licenses_fuzzy', []):
63+
# import pdb; pdb.set_trace()
64+
row = {
65+
'component': component,
66+
'file path': license['path'],
67+
'file name': os.path.basename(license['path']),
68+
'archive context': None,
69+
'usage(s)': None,
70+
'license(s)': license['licenseGroupName'],
71+
'source': 'KB',
72+
'origin(s)': origin.get('originName'),
73+
'origin_id(s)': origin.get('originId'),
74+
'copyright': None
75+
}
76+
writer.writerow(row)
77+
78+
for copyright in origin.get('file_copyrights', []):
79+
# import pdb; pdb.set_trace()
80+
row = {
81+
'component': component,
82+
'file path': copyright['path'],
83+
'file name': os.path.basename(copyright['path']),
84+
'archive context': None,
85+
'usage(s)': None,
86+
'license(s)': None,
87+
'source': 'KB',
88+
'origin(s)': origin.get('originName'),
89+
'origin_id(s)': origin.get('originId'),
90+
'copyright': copyright['matchData'].replace('\n', ''),
91+
}
92+
writer.writerow(row)
93+
94+
5995
if args.un_matched_files:
6096
for un_matched_file in origin_info.get('un_matched_files'):
6197
uri = urllib.parse.unquote(un_matched_file['uri'])

0 commit comments

Comments
 (0)