Skip to content

Commit b36d96e

Browse files
author
Glenn Snyder
committed
adding options for writing out file level license, copyright info
1 parent b264859 commit b36d96e

File tree

1 file changed

+36
-32
lines changed

1 file changed

+36
-32
lines changed

examples/convert_bom_component_origin_info_to_csv.py

Lines changed: 36 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
parser = argparse.ArgumentParser("Process the JSON output from get_bom_component_origin_info.py to create CSV output format")
1010
parser.add_argument("-f", "--origin_info", help="By default, program reads JSON doc from stdin, but you can alternatively give a file name")
1111
parser.add_argument("-u", "--un_matched_files", action="store_true", help="Include un-matched files in the output")
12+
parser.add_argument("-l", "--file_level_license", action="store_true", help="Include file level license data, if present")
13+
parser.add_argument("-c", "--file_level_copyright", action="store_true", help="Include file level copyright data, if present")
1214
parser.add_argument("output_file")
1315

1416
args = parser.parse_args()
@@ -58,39 +60,41 @@
5860
}
5961
writer.writerow(row)
6062

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)
63+
if args.file_level_license or args.file_level_copyright:
64+
for origin in component_info.get('all_origin_details', []):
65+
if args.file_level_license:
66+
for license in origin.get('file_licenses_fuzzy', []):
67+
# import pdb; pdb.set_trace()
68+
row = {
69+
'component': component,
70+
'file path': license['path'],
71+
'file name': os.path.basename(license['path']),
72+
'archive context': None,
73+
'usage(s)': None,
74+
'license(s)': license['licenseGroupName'],
75+
'source': 'KB',
76+
'origin(s)': origin.get('originName'),
77+
'origin_id(s)': origin.get('originId'),
78+
'copyright': None
79+
}
80+
writer.writerow(row)
9381

82+
if args.file_level_copyright:
83+
for copyright in origin.get('file_copyrights', []):
84+
# import pdb; pdb.set_trace()
85+
row = {
86+
'component': component,
87+
'file path': copyright['path'],
88+
'file name': os.path.basename(copyright['path']),
89+
'archive context': None,
90+
'usage(s)': None,
91+
'license(s)': None,
92+
'source': 'KB',
93+
'origin(s)': origin.get('originName'),
94+
'origin_id(s)': origin.get('originId'),
95+
'copyright': copyright['matchData'].replace('\n', ''),
96+
}
97+
writer.writerow(row)
9498

9599
if args.un_matched_files:
96100
for un_matched_file in origin_info.get('un_matched_files'):

0 commit comments

Comments
 (0)