|
9 | 9 | parser = argparse.ArgumentParser("Process the JSON output from get_bom_component_origin_info.py to create CSV output format")
|
10 | 10 | parser.add_argument("-f", "--origin_info", help="By default, program reads JSON doc from stdin, but you can alternatively give a file name")
|
11 | 11 | 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") |
12 | 14 | parser.add_argument("output_file")
|
13 | 15 |
|
14 | 16 | args = parser.parse_args()
|
|
58 | 60 | }
|
59 | 61 | writer.writerow(row)
|
60 | 62 |
|
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) |
93 | 81 |
|
| 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) |
94 | 98 |
|
95 | 99 | if args.un_matched_files:
|
96 | 100 | for un_matched_file in origin_info.get('un_matched_files'):
|
|
0 commit comments