fosslight-util 1.4.34__py3-none-any.whl → 2.1.28__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- fosslight_util/_get_downloadable_url.py +466 -36
- fosslight_util/compare_yaml.py +20 -11
- fosslight_util/constant.py +35 -0
- fosslight_util/correct.py +46 -78
- fosslight_util/cover.py +60 -0
- fosslight_util/download.py +302 -95
- fosslight_util/exclude.py +65 -0
- fosslight_util/help.py +20 -8
- fosslight_util/oss_item.py +171 -110
- fosslight_util/output_format.py +147 -19
- fosslight_util/parsing_yaml.py +45 -23
- fosslight_util/read_excel.py +40 -39
- fosslight_util/set_log.py +30 -5
- fosslight_util/spdx_licenses.py +2 -1
- fosslight_util/write_cyclonedx.py +210 -0
- fosslight_util/write_excel.py +141 -133
- fosslight_util/write_opossum.py +14 -20
- fosslight_util/write_scancodejson.py +51 -32
- fosslight_util/write_spdx.py +162 -115
- fosslight_util/write_txt.py +2 -1
- fosslight_util/write_yaml.py +43 -49
- {fosslight_util-1.4.34.dist-info → fosslight_util-2.1.28.dist-info}/METADATA +32 -24
- fosslight_util-2.1.28.dist-info/RECORD +32 -0
- {fosslight_util-1.4.34.dist-info → fosslight_util-2.1.28.dist-info}/WHEEL +1 -1
- {fosslight_util-1.4.34.dist-info → fosslight_util-2.1.28.dist-info}/entry_points.txt +0 -1
- fosslight_util/convert_excel_to_yaml.py +0 -69
- fosslight_util-1.4.34.dist-info/RECORD +0 -30
- {fosslight_util-1.4.34.dist-info → fosslight_util-2.1.28.dist-info/licenses}/LICENSE +0 -0
- {fosslight_util-1.4.34.dist-info → fosslight_util-2.1.28.dist-info}/top_level.txt +0 -0
fosslight_util/write_excel.py
CHANGED
|
@@ -7,151 +7,102 @@ import csv
|
|
|
7
7
|
import time
|
|
8
8
|
import logging
|
|
9
9
|
import os
|
|
10
|
-
import platform
|
|
11
10
|
import pandas as pd
|
|
12
|
-
import copy
|
|
13
11
|
from pathlib import Path
|
|
14
|
-
|
|
12
|
+
from fosslight_util.constant import LOGGER_NAME, SHEET_NAME_FOR_SCANNER, FOSSLIGHT_BINARY
|
|
15
13
|
from jsonmerge import merge
|
|
16
14
|
|
|
17
|
-
_HEADER = {'BIN (': ['ID', 'Binary
|
|
15
|
+
_HEADER = {'BIN (': ['ID', 'Binary Path', 'Source Code Path',
|
|
18
16
|
'NOTICE.html', 'OSS Name', 'OSS Version',
|
|
19
17
|
'License', 'Download Location', 'Homepage',
|
|
20
18
|
'Copyright Text', 'Exclude', 'Comment'],
|
|
21
|
-
'SRC': ['ID', 'Source
|
|
22
|
-
'OSS Version', 'License', 'Download Location',
|
|
23
|
-
'Homepage', 'Copyright Text', 'Exclude',
|
|
24
|
-
'Comment'],
|
|
25
|
-
'BIN': ['ID', 'Binary Name', 'OSS Name', 'OSS Version',
|
|
19
|
+
'SRC': ['ID', 'Source Path', 'OSS Name', 'OSS Version',
|
|
26
20
|
'License', 'Download Location', 'Homepage',
|
|
27
|
-
'Copyright Text', 'Exclude', 'Comment']
|
|
21
|
+
'Copyright Text', 'Exclude', 'Comment'],
|
|
22
|
+
'BIN': ['ID', 'Binary Path', 'OSS Name', 'OSS Version',
|
|
23
|
+
'License', 'Download Location', 'Homepage',
|
|
24
|
+
'Copyright Text', 'Exclude', 'Comment',
|
|
25
|
+
'Vulnerability Link', 'TLSH', 'SHA1'],
|
|
26
|
+
'DEP': ['ID', 'Package URL', 'OSS Name', 'OSS Version',
|
|
27
|
+
'License', 'Download Location', 'Homepage',
|
|
28
|
+
'Copyright Text', 'Exclude', 'Comment',
|
|
29
|
+
'Depends On']}
|
|
30
|
+
|
|
31
|
+
BIN_HIDE_HEADER = {'TLSH', "SHA1"}
|
|
28
32
|
_OUTPUT_FILE_PREFIX = "FOSSLight-Report_"
|
|
29
|
-
_EMPTY_ITEM_MSG = "* There is no item"\
|
|
30
|
-
" to print in FOSSLight-Report.\n"
|
|
31
33
|
IDX_FILE = 0
|
|
32
34
|
IDX_EXCLUDE = 7
|
|
33
|
-
logger = logging.getLogger(
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
def write_excel_and_csv(filename_without_extension, sheet_list, ignore_os=False, extended_header={}):
|
|
37
|
-
success = True
|
|
38
|
-
error_msg = ""
|
|
39
|
-
success_csv = True
|
|
40
|
-
error_msg_csv = ""
|
|
41
|
-
output_files = ""
|
|
42
|
-
output_csv = ""
|
|
43
|
-
|
|
44
|
-
is_not_null, sheet_list = remove_empty_sheet(sheet_list)
|
|
45
|
-
|
|
46
|
-
if is_not_null:
|
|
47
|
-
output_dir = os.path.dirname(filename_without_extension)
|
|
48
|
-
Path(output_dir).mkdir(parents=True, exist_ok=True)
|
|
35
|
+
logger = logging.getLogger(LOGGER_NAME)
|
|
36
|
+
COVER_SHEET_NAME = 'Scanner Info'
|
|
37
|
+
MAX_EXCEL_URL_LENGTH = 255
|
|
49
38
|
|
|
50
|
-
success, error_msg = write_result_to_excel(f"{filename_without_extension}.xlsx", sheet_list, extended_header)
|
|
51
|
-
|
|
52
|
-
if ignore_os or platform.system() != "Windows":
|
|
53
|
-
success_csv, error_msg_csv, output_csv = write_result_to_csv(f"{filename_without_extension}.csv",
|
|
54
|
-
sheet_list, True, extended_header)
|
|
55
|
-
if success:
|
|
56
|
-
output_files = f"{filename_without_extension}.xlsx"
|
|
57
|
-
else:
|
|
58
|
-
error_msg = "[Error] Writing excel:" + error_msg
|
|
59
|
-
if success_csv:
|
|
60
|
-
if output_csv:
|
|
61
|
-
output_files = f"{output_files}, {output_csv}" if output_files else output_csv
|
|
62
|
-
else:
|
|
63
|
-
error_msg += "\n[Error] Writing csv:" + error_msg_csv
|
|
64
|
-
else:
|
|
65
|
-
success = False
|
|
66
|
-
error_msg = _EMPTY_ITEM_MSG
|
|
67
|
-
|
|
68
|
-
return (success and success_csv), error_msg, output_files
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
def remove_empty_sheet(sheet_items):
|
|
72
|
-
skip_sheet_name = []
|
|
73
|
-
cnt_sheet_to_print = 0
|
|
74
|
-
final_sheet_to_print = {}
|
|
75
|
-
success = False
|
|
76
|
-
try:
|
|
77
|
-
if sheet_items:
|
|
78
|
-
for sheet_name, sheet_content in sheet_items.items():
|
|
79
|
-
if len(sheet_content) > 0:
|
|
80
|
-
final_sheet_to_print[sheet_name] = sheet_content
|
|
81
|
-
cnt_sheet_to_print += 1
|
|
82
|
-
else:
|
|
83
|
-
skip_sheet_name.append(sheet_name)
|
|
84
|
-
if cnt_sheet_to_print != 0:
|
|
85
|
-
success = True
|
|
86
|
-
if len(skip_sheet_name) > 0:
|
|
87
|
-
logger.warn("* Empty sheet(not printed):" + str(skip_sheet_name))
|
|
88
|
-
except Exception as ex:
|
|
89
|
-
logger.warn("* Warning:"+str(ex))
|
|
90
|
-
|
|
91
|
-
return success, final_sheet_to_print
|
|
92
39
|
|
|
93
|
-
|
|
94
|
-
def get_header_row(sheet_name, sheet_content, extended_header={}):
|
|
40
|
+
def get_header_row(sheet_name, extended_header={}):
|
|
95
41
|
selected_header = []
|
|
96
42
|
|
|
97
43
|
merged_headers = merge(_HEADER, extended_header)
|
|
98
44
|
|
|
99
|
-
selected_header = merged_headers.get(sheet_name)
|
|
45
|
+
selected_header = merged_headers.get(sheet_name, [])
|
|
100
46
|
if not selected_header:
|
|
101
47
|
for header_key in merged_headers.keys():
|
|
102
48
|
if sheet_name.startswith(header_key):
|
|
103
49
|
selected_header = merged_headers[header_key]
|
|
104
50
|
break
|
|
105
|
-
|
|
106
|
-
if not selected_header:
|
|
107
|
-
selected_header = sheet_content.pop(0)
|
|
108
|
-
return selected_header, sheet_content
|
|
51
|
+
return selected_header
|
|
109
52
|
|
|
110
53
|
|
|
111
|
-
def write_result_to_csv(output_file,
|
|
54
|
+
def write_result_to_csv(output_file, scan_item, separate_sheet=False, extended_header={}):
|
|
112
55
|
success = True
|
|
113
56
|
error_msg = ""
|
|
114
57
|
file_extension = ".csv"
|
|
115
58
|
output = ""
|
|
116
59
|
|
|
117
60
|
try:
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
61
|
+
output_files = []
|
|
62
|
+
output_dir = os.path.dirname(output_file)
|
|
63
|
+
Path(output_dir).mkdir(parents=True, exist_ok=True)
|
|
64
|
+
if separate_sheet:
|
|
65
|
+
filename = os.path.splitext(os.path.basename(output_file))[0]
|
|
66
|
+
separate_output_file = os.path.join(output_dir, filename)
|
|
67
|
+
|
|
68
|
+
merge_sheet = []
|
|
69
|
+
for scanner_name, _ in scan_item.file_items.items():
|
|
70
|
+
row_num = 1
|
|
71
|
+
sheet_name = ""
|
|
72
|
+
if scanner_name.lower() in SHEET_NAME_FOR_SCANNER:
|
|
73
|
+
sheet_name = SHEET_NAME_FOR_SCANNER[scanner_name.lower()]
|
|
74
|
+
elif extended_header:
|
|
75
|
+
sheet_name = list(extended_header.keys())[0]
|
|
76
|
+
sheet_content_without_header = scan_item.get_print_array(scanner_name)
|
|
77
|
+
header_row = get_header_row(sheet_name, extended_header)
|
|
78
|
+
|
|
79
|
+
if 'Copyright Text' in header_row:
|
|
80
|
+
idx = header_row.index('Copyright Text')-1
|
|
81
|
+
for item in sheet_content_without_header:
|
|
82
|
+
item[idx] = item[idx].replace('\n', ', ')
|
|
83
|
+
if not separate_sheet:
|
|
84
|
+
merge_sheet.extend(sheet_content_without_header)
|
|
85
|
+
if scanner_name == list(scan_item.file_items.keys())[-1]:
|
|
86
|
+
sheet_content_without_header = merge_sheet
|
|
138
87
|
else:
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
88
|
+
continue
|
|
89
|
+
else:
|
|
90
|
+
output_file = separate_output_file + "_" + sheet_name + file_extension
|
|
91
|
+
try:
|
|
92
|
+
sheet_content_without_header = sorted(sheet_content_without_header,
|
|
93
|
+
key=lambda x: (x[IDX_EXCLUDE], x[IDX_FILE] == "", x[IDX_FILE]))
|
|
94
|
+
except Exception:
|
|
95
|
+
pass
|
|
96
|
+
with open(output_file, 'w', newline='') as file:
|
|
97
|
+
writer = csv.writer(file, delimiter='\t')
|
|
98
|
+
writer.writerow(header_row)
|
|
99
|
+
for row_item in sheet_content_without_header:
|
|
100
|
+
row_item.insert(0, row_num)
|
|
101
|
+
writer.writerow(row_item)
|
|
102
|
+
row_num += 1
|
|
103
|
+
output_files.append(output_file)
|
|
104
|
+
if output_files:
|
|
105
|
+
output = ", ".join(output_files)
|
|
155
106
|
except Exception as ex:
|
|
156
107
|
error_msg = str(ex)
|
|
157
108
|
success = False
|
|
@@ -159,52 +110,104 @@ def write_result_to_csv(output_file, sheet_list_origin, separate_sheet=False, ex
|
|
|
159
110
|
return success, error_msg, output
|
|
160
111
|
|
|
161
112
|
|
|
162
|
-
def write_result_to_excel(out_file_name,
|
|
113
|
+
def write_result_to_excel(out_file_name, scan_item, extended_header={}, hide_header={}):
|
|
163
114
|
success = True
|
|
164
115
|
error_msg = ""
|
|
165
116
|
|
|
166
117
|
try:
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
Path(output_dir).mkdir(parents=True, exist_ok=True)
|
|
118
|
+
output_dir = os.path.dirname(out_file_name)
|
|
119
|
+
Path(output_dir).mkdir(parents=True, exist_ok=True)
|
|
170
120
|
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
121
|
+
workbook = xlsxwriter.Workbook(out_file_name)
|
|
122
|
+
write_cover_sheet(workbook, scan_item.cover)
|
|
123
|
+
if scan_item.file_items and len(scan_item.file_items.keys()) > 0:
|
|
124
|
+
for scanner_name, _ in scan_item.file_items.items():
|
|
125
|
+
sheet_name = ""
|
|
126
|
+
if scanner_name.lower() in SHEET_NAME_FOR_SCANNER:
|
|
127
|
+
sheet_name = SHEET_NAME_FOR_SCANNER[scanner_name.lower()]
|
|
128
|
+
elif extended_header:
|
|
129
|
+
sheet_name = list(extended_header.keys())[0]
|
|
130
|
+
sheet_content_without_header = scan_item.get_print_array(scanner_name)
|
|
131
|
+
selected_header = get_header_row(sheet_name, extended_header)
|
|
174
132
|
try:
|
|
175
133
|
sheet_content_without_header = sorted(sheet_content_without_header,
|
|
176
134
|
key=lambda x: (x[IDX_EXCLUDE], x[IDX_FILE] == "", x[IDX_FILE]))
|
|
177
135
|
except Exception:
|
|
178
136
|
pass
|
|
137
|
+
if sheet_name:
|
|
138
|
+
worksheet = create_worksheet(workbook, sheet_name, selected_header)
|
|
139
|
+
write_result_to_sheet(worksheet, sheet_content_without_header)
|
|
140
|
+
if (scanner_name == FOSSLIGHT_BINARY) and (not hide_header):
|
|
141
|
+
hide_header = BIN_HIDE_HEADER
|
|
142
|
+
if hide_header:
|
|
143
|
+
hide_column(worksheet, selected_header, hide_header)
|
|
144
|
+
|
|
145
|
+
for sheet_name, content in scan_item.external_sheets.items():
|
|
146
|
+
if len(content) > 0:
|
|
147
|
+
selected_header = content.pop(0)
|
|
179
148
|
worksheet = create_worksheet(workbook, sheet_name, selected_header)
|
|
180
|
-
write_result_to_sheet(worksheet,
|
|
181
|
-
|
|
149
|
+
write_result_to_sheet(worksheet, content)
|
|
150
|
+
if hide_header:
|
|
151
|
+
hide_column(worksheet, selected_header, hide_header)
|
|
152
|
+
|
|
153
|
+
workbook.close()
|
|
182
154
|
except Exception as ex:
|
|
183
155
|
error_msg = str(ex)
|
|
184
156
|
success = False
|
|
185
157
|
return success, error_msg
|
|
186
158
|
|
|
187
159
|
|
|
160
|
+
def write_cover_sheet(workbook, cover):
|
|
161
|
+
worksheet = workbook.add_worksheet(COVER_SHEET_NAME)
|
|
162
|
+
|
|
163
|
+
format_bold = workbook.add_format({'bold': True})
|
|
164
|
+
worksheet.merge_range('A1:B1', 'About the scanner', format_bold)
|
|
165
|
+
|
|
166
|
+
key_format = workbook.add_format({'bold': True, 'font_color': 'white', 'bg_color': 'navy'})
|
|
167
|
+
item_format = workbook.add_format()
|
|
168
|
+
item_format.set_text_wrap()
|
|
169
|
+
|
|
170
|
+
cover_json = cover.get_print_json()
|
|
171
|
+
row = 1
|
|
172
|
+
for item in cover_json:
|
|
173
|
+
worksheet.write(row, 0, item, key_format)
|
|
174
|
+
worksheet.write(row, 1, cover_json[item], item_format)
|
|
175
|
+
row += 1
|
|
176
|
+
worksheet.set_column(0, 0, 30)
|
|
177
|
+
worksheet.set_column(1, 1, 100)
|
|
178
|
+
|
|
179
|
+
|
|
188
180
|
def write_result_to_sheet(worksheet, sheet_contents):
|
|
189
181
|
row = 1
|
|
190
182
|
for row_item in sheet_contents:
|
|
191
183
|
worksheet.write(row, 0, row)
|
|
192
184
|
for col_num, value in enumerate(row_item):
|
|
193
|
-
|
|
185
|
+
if len(value) > MAX_EXCEL_URL_LENGTH and (value.startswith("http://") or value.startswith("https://")):
|
|
186
|
+
worksheet.write_string(row, col_num + 1, str(value))
|
|
187
|
+
else:
|
|
188
|
+
worksheet.write(row, col_num + 1, str(value))
|
|
194
189
|
row += 1
|
|
195
190
|
|
|
196
191
|
|
|
192
|
+
def hide_column(worksheet, selected_header, hide_header):
|
|
193
|
+
for col_idx, sel_hd in enumerate(selected_header):
|
|
194
|
+
for hide_hd in hide_header:
|
|
195
|
+
if str(sel_hd).lower() == str(hide_hd).lower():
|
|
196
|
+
worksheet.set_column(col_idx, col_idx, None, None, {"hidden": True})
|
|
197
|
+
|
|
198
|
+
|
|
197
199
|
def create_worksheet(workbook, sheet_name, header_row):
|
|
198
200
|
if len(sheet_name) > 31:
|
|
199
201
|
current_time = str(time.time())
|
|
200
202
|
sheet_name = current_time
|
|
201
203
|
worksheet = workbook.add_worksheet(sheet_name)
|
|
202
|
-
|
|
203
|
-
|
|
204
|
+
if header_row:
|
|
205
|
+
for col_num, value in enumerate(header_row):
|
|
206
|
+
worksheet.write(0, col_num, value)
|
|
204
207
|
return worksheet
|
|
205
208
|
|
|
206
209
|
|
|
207
|
-
def merge_excels(find_excel_dir, final_out, merge_files=''):
|
|
210
|
+
def merge_excels(find_excel_dir, final_out, merge_files='', cover=''):
|
|
208
211
|
success = True
|
|
209
212
|
msg = ""
|
|
210
213
|
FIND_EXTENSION = '.xlsx'
|
|
@@ -214,7 +217,7 @@ def merge_excels(find_excel_dir, final_out, merge_files=''):
|
|
|
214
217
|
|
|
215
218
|
if len([name for name in files if name.endswith(FIND_EXTENSION)]) > 0:
|
|
216
219
|
writer = pd.ExcelWriter(final_out)
|
|
217
|
-
|
|
220
|
+
write_cover_sheet(writer.book, cover)
|
|
218
221
|
for file in files:
|
|
219
222
|
if merge_files:
|
|
220
223
|
if file not in merge_files:
|
|
@@ -226,13 +229,18 @@ def merge_excels(find_excel_dir, final_out, merge_files=''):
|
|
|
226
229
|
excel_file = pd.ExcelFile(file, engine='openpyxl')
|
|
227
230
|
|
|
228
231
|
for sheet_name in excel_file.sheet_names:
|
|
229
|
-
|
|
232
|
+
if sheet_name == COVER_SHEET_NAME:
|
|
233
|
+
continue
|
|
230
234
|
df_excel = pd.read_excel(
|
|
231
235
|
file, sheet_name=sheet_name, engine='openpyxl')
|
|
232
|
-
if sheet_name
|
|
233
|
-
|
|
234
|
-
df_excel.to_excel(writer,
|
|
235
|
-
|
|
236
|
+
if sheet_name in added_sheet_names:
|
|
237
|
+
sheet_name = f"{f_short_name}_{sheet_name}"
|
|
238
|
+
df_excel.to_excel(writer, sheet_name, index=False)
|
|
239
|
+
added_sheet_names.append(sheet_name)
|
|
240
|
+
|
|
241
|
+
if sheet_name == 'BIN_FL_Binary':
|
|
242
|
+
bin_sheet = writer.sheets[sheet_name]
|
|
243
|
+
bin_sheet.set_column("L:M", None, None, {"hidden": True}) # 'TLSH', 'SHA1' column hide
|
|
236
244
|
writer.close()
|
|
237
245
|
except Exception as ex:
|
|
238
246
|
msg = str(ex)
|
fosslight_util/write_opossum.py
CHANGED
|
@@ -11,9 +11,8 @@ import logging
|
|
|
11
11
|
from datetime import datetime
|
|
12
12
|
from pathlib import Path
|
|
13
13
|
import traceback
|
|
14
|
-
from
|
|
15
|
-
|
|
16
|
-
import fosslight_util.constant as constant
|
|
14
|
+
from fosslight_util.constant import LOGGER_NAME, FOSSLIGHT_BINARY, FOSSLIGHT_DEPENDENCY, FOSSLIGHT_SOURCE
|
|
15
|
+
from typing import Dict, Optional, Tuple
|
|
17
16
|
|
|
18
17
|
|
|
19
18
|
PACKAGE = {
|
|
@@ -30,7 +29,7 @@ PACKAGE = {
|
|
|
30
29
|
}
|
|
31
30
|
|
|
32
31
|
_attributionConfidence = 80
|
|
33
|
-
logger = logging.getLogger(
|
|
32
|
+
logger = logging.getLogger(LOGGER_NAME)
|
|
34
33
|
|
|
35
34
|
|
|
36
35
|
class AttributionItem():
|
|
@@ -51,7 +50,7 @@ class AttributionItem():
|
|
|
51
50
|
self.excludeFromNotice = False
|
|
52
51
|
|
|
53
52
|
self.source_name = source_name
|
|
54
|
-
if source_name ==
|
|
53
|
+
if source_name == FOSSLIGHT_DEPENDENCY:
|
|
55
54
|
self.preSelected = True
|
|
56
55
|
else:
|
|
57
56
|
self.preSelected = False
|
|
@@ -113,12 +112,12 @@ class Attribution(AttributionItem):
|
|
|
113
112
|
dict[licenseName] = self.licenseName
|
|
114
113
|
dict[preSelected] = self.preSelected
|
|
115
114
|
|
|
116
|
-
if self.source_name ==
|
|
115
|
+
if self.source_name == FOSSLIGHT_SOURCE or FOSSLIGHT_BINARY:
|
|
117
116
|
dict[copyright] = self.copyright
|
|
118
117
|
dict[packageName] = self.packageName
|
|
119
118
|
dict[packageVersion] = self.packageVersion
|
|
120
119
|
dict[url] = self.url
|
|
121
|
-
elif self.source_name ==
|
|
120
|
+
elif self.source_name == FOSSLIGHT_DEPENDENCY:
|
|
122
121
|
dict[copyright] = self.copyright
|
|
123
122
|
dict[packageName] = self.packageName
|
|
124
123
|
dict[packageVersion] = self.packageVersion
|
|
@@ -165,7 +164,7 @@ def make_frequentlicenses():
|
|
|
165
164
|
return frequentLicenses, success, error_msg
|
|
166
165
|
|
|
167
166
|
|
|
168
|
-
def write_opossum(filename,
|
|
167
|
+
def write_opossum(filename: str, scan_item) -> Tuple[bool, str]:
|
|
169
168
|
success = True
|
|
170
169
|
error_msg = ''
|
|
171
170
|
dict = {}
|
|
@@ -176,7 +175,7 @@ def write_opossum(filename, sheet_list):
|
|
|
176
175
|
_filesWithChildren_key = 'filesWithChildren'
|
|
177
176
|
_attributionBreakpoints_key = 'attributionBreakpoints'
|
|
178
177
|
|
|
179
|
-
if
|
|
178
|
+
if scan_item:
|
|
180
179
|
output_dir = os.path.dirname(filename)
|
|
181
180
|
Path(output_dir).mkdir(parents=True, exist_ok=True)
|
|
182
181
|
|
|
@@ -189,14 +188,9 @@ def write_opossum(filename, sheet_list):
|
|
|
189
188
|
filesWithChildren_list = []
|
|
190
189
|
attributionBreakpoints_list = []
|
|
191
190
|
try:
|
|
192
|
-
for
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
else:
|
|
196
|
-
logger.warning("Not supported scanner(sheet_name):" + sheet_name)
|
|
197
|
-
continue
|
|
198
|
-
|
|
199
|
-
ret_resources_attribution = make_resources_and_attributions(sheet_contents, scanner, resources, fc_list)
|
|
191
|
+
for scanner_name, _ in scan_item.file_items.items():
|
|
192
|
+
sheet_contents = scan_item.get_print_array(scanner_name)
|
|
193
|
+
ret_resources_attribution = make_resources_and_attributions(sheet_contents, scanner_name, resources, fc_list)
|
|
200
194
|
success, rsc, ea, ra, fl, ab = ret_resources_attribution
|
|
201
195
|
if success:
|
|
202
196
|
dict[_resources_key].update(rsc)
|
|
@@ -255,14 +249,14 @@ def make_resources_and_attributions(sheet_items, scanner, resources, fc_list):
|
|
|
255
249
|
items = items[0:9]
|
|
256
250
|
path, oss_name, oss_version, license, url, homepage, copyright, exclude, comment = items
|
|
257
251
|
|
|
258
|
-
if scanner ==
|
|
252
|
+
if scanner == FOSSLIGHT_SOURCE:
|
|
259
253
|
if (os.path.join(os.sep, path) + os.sep) not in fc_list:
|
|
260
254
|
resources = make_resources(path, resources)
|
|
261
255
|
attribution = Attribution(scanner, license, exclude, copyright, oss_name, oss_version, url)
|
|
262
|
-
elif scanner ==
|
|
256
|
+
elif scanner == FOSSLIGHT_BINARY:
|
|
263
257
|
resources = make_resources(path, resources)
|
|
264
258
|
attribution = Attribution(scanner, license, exclude, copyright, oss_name, oss_version, url)
|
|
265
|
-
elif scanner ==
|
|
259
|
+
elif scanner == FOSSLIGHT_DEPENDENCY:
|
|
266
260
|
try:
|
|
267
261
|
packageType = PACKAGE[path]
|
|
268
262
|
except Exception:
|
|
@@ -6,57 +6,76 @@
|
|
|
6
6
|
import logging
|
|
7
7
|
import os
|
|
8
8
|
import json
|
|
9
|
-
|
|
9
|
+
from fosslight_util.constant import LOGGER_NAME, FOSSLIGHT_DEPENDENCY
|
|
10
|
+
from fosslight_util.oss_item import ScannerItem
|
|
11
|
+
from typing import List
|
|
10
12
|
|
|
11
|
-
logger = logging.getLogger(
|
|
13
|
+
logger = logging.getLogger(LOGGER_NAME)
|
|
12
14
|
EMPTY_FILE_PATH = '-'
|
|
13
15
|
|
|
14
16
|
|
|
15
|
-
def write_scancodejson(output_dir, output_filename, oss_list):
|
|
17
|
+
def write_scancodejson(output_dir: str, output_filename: str, oss_list: List[ScannerItem]):
|
|
16
18
|
json_output = {}
|
|
17
19
|
json_output['headers'] = []
|
|
18
20
|
json_output['summary'] = {}
|
|
19
21
|
json_output['license_detections'] = []
|
|
20
22
|
json_output['files'] = []
|
|
23
|
+
json_output['dependencies'] = []
|
|
21
24
|
|
|
22
|
-
for
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
oi.source_name_or_path = EMPTY_FILE_PATH
|
|
27
|
-
for item_path in oi.source_name_or_path:
|
|
28
|
-
filtered = next(filter(lambda x: x['path'] == item_path, json_output['files']), None)
|
|
29
|
-
if filtered:
|
|
30
|
-
append_oss_item_in_filesitem(oi, filtered)
|
|
25
|
+
for scanner, file_items in oss_list.file_items.items():
|
|
26
|
+
for fi in file_items:
|
|
27
|
+
if scanner == FOSSLIGHT_DEPENDENCY:
|
|
28
|
+
json_output['dependencies'] = add_item_in_deps(fi, json_output['dependencies'])
|
|
31
29
|
else:
|
|
32
|
-
|
|
30
|
+
if fi.exclude:
|
|
31
|
+
continue
|
|
32
|
+
if fi.oss_items and (all(oss_item.exclude for oss_item in fi.oss_items)):
|
|
33
|
+
continue
|
|
34
|
+
if not fi.source_name_or_path:
|
|
35
|
+
fi.source_name_or_path = EMPTY_FILE_PATH
|
|
36
|
+
json_output['files'] = add_item_in_files(fi, json_output['files'])
|
|
37
|
+
|
|
33
38
|
with open(os.path.join(output_dir, output_filename), 'w') as f:
|
|
34
39
|
json.dump(json_output, f, sort_keys=False, indent=4)
|
|
35
40
|
|
|
36
41
|
|
|
37
|
-
def
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
42
|
+
def get_oss_item_list(oss_items):
|
|
43
|
+
scan_oss_items = []
|
|
44
|
+
for oi in oss_items:
|
|
45
|
+
if oi.exclude:
|
|
46
|
+
continue
|
|
41
47
|
oss_item = {}
|
|
42
|
-
oss_item['name'] =
|
|
43
|
-
oss_item['version'] =
|
|
44
|
-
oss_item['license'] =
|
|
45
|
-
oss_item['copyright'] =
|
|
46
|
-
oss_item['download_location'] =
|
|
47
|
-
oss_item['comment'] =
|
|
48
|
-
|
|
49
|
-
|
|
48
|
+
oss_item['name'] = oi.name
|
|
49
|
+
oss_item['version'] = oi.version
|
|
50
|
+
oss_item['license'] = oi.license
|
|
51
|
+
oss_item['copyright'] = oi.copyright
|
|
52
|
+
oss_item['download_location'] = oi.download_location
|
|
53
|
+
oss_item['comment'] = oi.comment
|
|
54
|
+
scan_oss_items.append(oss_item)
|
|
55
|
+
|
|
56
|
+
return scan_oss_items
|
|
50
57
|
|
|
51
58
|
|
|
52
|
-
def add_item_in_files(
|
|
59
|
+
def add_item_in_files(file_item, files_list):
|
|
53
60
|
files_item = {}
|
|
54
|
-
files_item['path'] =
|
|
55
|
-
files_item['name'] = os.path.basename(
|
|
56
|
-
files_item['is_binary'] =
|
|
57
|
-
files_item['base_name'], files_item['extension'] = os.path.splitext(os.path.basename(
|
|
58
|
-
files_item['oss'] =
|
|
59
|
-
|
|
61
|
+
files_item['path'] = file_item.source_name_or_path
|
|
62
|
+
files_item['name'] = os.path.basename(file_item.source_name_or_path)
|
|
63
|
+
files_item['is_binary'] = file_item.is_binary
|
|
64
|
+
files_item['base_name'], files_item['extension'] = os.path.splitext(os.path.basename(file_item.source_name_or_path))
|
|
65
|
+
files_item['oss'] = get_oss_item_list(file_item.oss_items)
|
|
66
|
+
|
|
60
67
|
files_list.append(files_item)
|
|
61
68
|
|
|
62
69
|
return files_list
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def add_item_in_deps(file_item, deps_list):
|
|
73
|
+
deps_item = {}
|
|
74
|
+
deps_item['purl'] = file_item.purl
|
|
75
|
+
deps_item['scope'] = 'dependencies'
|
|
76
|
+
deps_item['depends_on'] = file_item.depends_on
|
|
77
|
+
deps_item['oss'] = get_oss_item_list(file_item.oss_items)
|
|
78
|
+
|
|
79
|
+
deps_list.append(deps_item)
|
|
80
|
+
|
|
81
|
+
return deps_list
|