Skip to content

Commit 2ec7ed7

Browse files
change download_location as list
1 parent 6e93c15 commit 2ec7ed7

File tree

4 files changed

+43
-20
lines changed

4 files changed

+43
-20
lines changed

src/fosslight_source/_parsing_scancode_file_item.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
from ._scan_item import is_exclude_dir
1414
from ._scan_item import is_exclude_file
1515
from ._scan_item import replace_word
16-
import copy
1716

1817
logger = logging.getLogger(constant.LOGGER_NAME)
1918
_exclude_directory = ["test", "tests", "doc", "docs"]
@@ -84,6 +83,7 @@ def parsing_file_item(scancode_file_list, has_error, path_to_scan, need_matched_
8483
with mmap.mmap(f.fileno(), 0, access=mmap.ACCESS_READ) as mmap_obj:
8584
for word in find_word.findall(mmap_obj):
8685
url_list.append(word.decode('utf-8'))
86+
result_item.download_location = url_list
8787

8888
if has_error and "scan_errors" in file:
8989
error_msg = file.get("scan_errors", [])
@@ -178,13 +178,7 @@ def parsing_file_item(scancode_file_list, has_error, path_to_scan, need_matched_
178178

179179
if is_exclude_file(file_path, prev_dir, prev_dir_value):
180180
result_item.exclude = True
181-
if url_list:
182-
for url in url_list:
183-
temp_result_item = copy.deepcopy(result_item)
184-
temp_result_item.download_location = url
185-
scancode_file_item.append(temp_result_item)
186-
else:
187-
scancode_file_item.append(result_item)
181+
scancode_file_item.append(result_item)
188182
except Exception as ex:
189183
msg.append(f"Error Parsing item: {ex}")
190184
rc = False

src/fosslight_source/_parsing_scanoss_file.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def parsing_scanResult(scanoss_report):
4848
if 'version' in findings[0]:
4949
result_item.oss_version = findings[0]['version']
5050
if 'url' in findings[0]:
51-
result_item.download_location = findings[0]['url']
51+
result_item.download_location = list([findings[0]['url']])
5252

5353
license_detected = []
5454
license_w_source = {"component_declared": [], "file_spdx_tag": [],

src/fosslight_source/_scan_item.py

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class ScanItem:
2727
is_license_text = False
2828
oss_name = ""
2929
oss_version = ""
30-
download_location = ""
30+
download_location = []
3131
matched_lines = "" # Only for SCANOSS results
3232
fileURL = "" # Only for SCANOSS results
3333
license_reference = ""
@@ -70,18 +70,38 @@ def get_row_to_print(self):
7070
print_rows = [self.file, self.oss_name, self.oss_version, ','.join(self.licenses),
7171
self.download_location, "", ','.join(self.copyright),
7272
"Exclude" if self.exclude else "", self.comment]
73+
print_rows = []
74+
if not self.download_location:
75+
print_rows.append([self.file, self.oss_name, self.oss_version, ','.join(self.licenses),
76+
"", "", ','.join(self.copyright), "Exclude" if self.exclude else "", self.comment])
77+
else:
78+
for url in self.download_location:
79+
print_rows.append([self.file, self.oss_name, self.oss_version, ','.join(self.licenses),
80+
url, "", ','.join(self.copyright), "Exclude" if self.exclude else "", self.comment])
7381
return print_rows
7482

7583
def get_row_to_print_for_scanoss(self):
76-
print_rows = [self.file, self.oss_name, self.oss_version, ','.join(self.licenses), self.download_location, "",
77-
','.join(self.copyright),
78-
"Exclude" if self.exclude else "", self.comment]
84+
print_rows = []
85+
if not self.download_location:
86+
print_rows.append([self.file, self.oss_name, self.oss_version, ','.join(self.licenses), "", "",
87+
','.join(self.copyright), "Exclude" if self.exclude else "", self.comment])
88+
else:
89+
for url in self.download_location:
90+
print_rows.append([self.file, self.oss_name, self.oss_version, ','.join(self.licenses), url, "",
91+
','.join(self.copyright), "Exclude" if self.exclude else "", self.comment])
7992
return print_rows
8093

8194
def get_row_to_print_for_all_scanner(self):
82-
print_rows = [self.file, self.oss_name, self.oss_version, ','.join(self.licenses), self.download_location, "",
83-
','.join(self.copyright),
84-
"Exclude" if self.exclude else "", self.comment, self.license_reference]
95+
print_rows = []
96+
if not self.download_location:
97+
print_rows.append([self.file, self.oss_name, self.oss_version, ','.join(self.licenses), "", "",
98+
','.join(self.copyright), "Exclude" if self.exclude else "", self.comment,
99+
self.license_reference])
100+
else:
101+
for url in self.download_location:
102+
print_rows.append([self.file, self.oss_name, self.oss_version, ','.join(self.licenses), url, "",
103+
','.join(self.copyright), "Exclude" if self.exclude else "", self.comment,
104+
self.license_reference])
85105
return print_rows
86106

87107
def merge_scan_item(self, other):
@@ -106,7 +126,7 @@ def merge_scan_item(self, other):
106126
if not self.oss_version:
107127
self.oss_version = other.oss_version
108128
if not self.download_location:
109-
self.download_location = other.download_location
129+
self.download_location = list(other.download_location)
110130
if not self.matched_lines:
111131
self.matched_lines = other.matched_lines
112132
if not self.fileURL:

src/fosslight_source/cli.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,14 +172,23 @@ def create_report_file(_start_time, scanned_result, license_list, scanoss_result
172172
scanned_result = sorted(scanned_result, key=lambda row: (''.join(row.licenses)))
173173

174174
if selected_scanner == 'scancode' or output_extension == _json_ext:
175-
sheet_list[SCANOSS_SHEET_NAME] = [scan_item.get_row_to_print() for scan_item in scanned_result]
175+
sheet_list[SCANOSS_SHEET_NAME] = []
176+
for scan_item in scanned_result:
177+
for row in scan_item.get_row_to_print():
178+
sheet_list[SCANOSS_SHEET_NAME].append(row)
176179

177180
elif selected_scanner == 'scanoss':
178-
sheet_list[SCANOSS_SHEET_NAME] = [scan_item.get_row_to_print_for_scanoss() for scan_item in scanned_result]
181+
sheet_list[SCANOSS_SHEET_NAME] = []
182+
for scan_item in scanned_result:
183+
for row in scan_item.get_row_to_print_for_scanoss():
184+
sheet_list[SCANOSS_SHEET_NAME].append(row)
179185
extended_header = SCANOSS_HEADER
180186

181187
else:
182-
sheet_list[SCANOSS_SHEET_NAME] = [scan_item.get_row_to_print_for_all_scanner() for scan_item in scanned_result]
188+
sheet_list[SCANOSS_SHEET_NAME] = []
189+
for scan_item in scanned_result:
190+
for row in scan_item.get_row_to_print_for_all_scanner():
191+
sheet_list[SCANOSS_SHEET_NAME].append(row)
183192
extended_header = MERGED_HEADER
184193

185194
if need_license:

0 commit comments

Comments
 (0)