Skip to content

Commit 155445f

Browse files
committed
CSV format updated
1 parent afe2a8e commit 155445f

File tree

1 file changed

+33
-3
lines changed

1 file changed

+33
-3
lines changed

examples/client/file_hierarchy_report.py

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,15 +157,45 @@ def trim_version_report(version_report, reduced_path_set):
157157
reduced_aggregate_bom_view_entries = [e for e in aggregate_bom_view_entries if f"{e['producerProject']['id']}:{e['producerReleases'][0]['id']}" in deduplicated]
158158
version_report['aggregateBomViewEntries'] = reduced_aggregate_bom_view_entries
159159

160+
'''
161+
162+
CSV output details
163+
164+
component name = aggregateBomViewEntries[].producerProject.name
165+
version name = aggregateBomViewEntries[].producerReleases[0].version
166+
license = licenses[].licenseDisplay
167+
file path = extract from detailedFileBomViewEntries
168+
match type = aggregateBomViewEntries[].matchTypes
169+
review status = aggregateBomViewEntries[].reviewSummary.reviewStatus
170+
171+
'''
172+
def get_csv_fieldnames():
173+
return ['component name', 'version name', 'license', 'file path', 'match type', 'review status']
174+
175+
def get_csv_data(version_report):
176+
csv_data = list()
177+
for bom_view_entry in version_report['aggregateBomViewEntries']:
178+
entry = dict()
179+
entry['component name'] = bom_view_entry['producerProject']['name']
180+
entry['version name'] = bom_view_entry['producerReleases'][0]['version']
181+
entry['license'] = bom_view_entry['licenses'][0]['licenseDisplay'].replace(' AND ',';').replace('(','').replace(')','')
182+
pid = bom_view_entry['producerProject']['id']
183+
vid = bom_view_entry['producerReleases'][0]['id']
184+
path_list = [p['path'] for p in version_report['detailedFileBomViewEntries'] if p['projectId'] == pid and p['versionId'] == vid]
185+
entry['file path'] = ';'.join(path_list)
186+
entry['match type'] = ';'.join(bom_view_entry['matchTypes'])
187+
entry['review status'] = bom_view_entry['reviewSummary']['reviewStatus']
188+
csv_data.append(entry)
189+
return csv_data
190+
160191
def write_output_file(version_report, output_file):
161192
if output_file.lower().endswith(".csv"):
162193
logging.info(f"Writing CSV output into {output_file}")
163-
field_names = list(version_report['aggregateBomViewEntries'][0].keys())
194+
field_names = get_csv_fieldnames()
164195
with open(output_file, "w") as f:
165196
writer = csv.DictWriter(f, fieldnames = field_names, extrasaction = 'ignore') # TODO
166197
writer.writeheader()
167-
writer.writerows(version_report['aggregateBomViewEntries'])
168-
198+
writer.writerows(get_csv_data(version_report))
169199
return
170200
# If it's neither, then .json
171201
if not output_file.lower().endswith(".json"):

0 commit comments

Comments
 (0)