Skip to content

Commit 4aec327

Browse files
Print SCANOSS info in a separate sheet
1 parent ff16a20 commit 4aec327

File tree

6 files changed

+80
-75
lines changed

6 files changed

+80
-75
lines changed

src/fosslight_source/_help.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
-h\t\t\t\t Print help message
2222
-v\t\t\t\t Print FOSSLight Source Scanner version
2323
-j\t\t\t\t Generate raw result of scanners in json format
24-
-m\t\t\t\t Print the Matched text for each license on a separate sheet (Scancode Only)
24+
-m\t\t\t\t Print additional information for scan result on separate sheets
2525
-o <output_path>\t\t Output path
2626
\t\t\t\t (If you want to generate the specific file name, add the output path with file name.)
2727
-f <format>\t\t\t Output file format (excel, csv, opossum)

src/fosslight_source/_parsing_scancode_file_item.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,12 @@ def parsing_file_item(scancode_file_list, has_error, need_matched_license=False)
7474
error_msg = file["scan_errors"]
7575
if len(error_msg) > 0:
7676
logger.debug(f"Test_msg {file_path}:{error_msg}")
77-
result_item.set_comment(",".join(error_msg))
77+
result_item.comment = ",".join(error_msg)
7878
scancode_file_item.append(result_item)
7979
continue
8080

8181
copyright_value_list = [x["value"] for x in copyright_list]
82-
result_item.set_copyright(copyright_value_list)
82+
result_item.copyright = copyright_value_list
8383

8484
# Set the license value
8585
license_detected = []
@@ -137,19 +137,18 @@ def parsing_file_item(scancode_file_list, has_error, need_matched_license=False)
137137

138138
matched_rule = lic_item["matched_rule"]
139139
if matched_rule["is_license_text"]:
140-
result_item.set_is_license_text(True)
140+
result_item.is_license_text = True
141141

142142
if len(license_detected) > 0:
143-
result_item.set_licenses(license_detected)
143+
result_item.licenses = license_detected
144144

145145
if len(license_expression_list) > 0:
146146
license_expression_list = list(
147147
set(license_expression_list))
148-
result_item.set_comment(
149-
','.join(license_expression_list))
148+
result_item.comment = ','.join(license_expression_list)
150149

151150
if is_exclude_file(file_path, prev_dir, prev_dir_value):
152-
result_item.set_exclude(True)
151+
result_item.exclude = True
153152
scancode_file_item.append(result_item)
154153

155154
except Exception as ex:

src/fosslight_source/_parsing_scanoss_file.py

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,25 @@
99
from ._scan_item import is_exclude_file
1010

1111
logger = logging.getLogger(constant.LOGGER_NAME)
12+
SCANOSS_INFO_HEADER = ['No', 'Source Name or Path', 'Component Declared', 'SPDX Tag',
13+
'File Header', 'License File', 'Scancode',
14+
'scanoss_matched_lines', 'scanoss_fileURL']
15+
16+
17+
def parsing_extraInfo(scanned_result):
18+
scanoss_extra_info = []
19+
for scan_item in scanned_result:
20+
license_w_source = scan_item.scanoss_reference
21+
if license_w_source:
22+
extra_item = [scan_item.file, ','.join(license_w_source['component_declared']),
23+
','.join(license_w_source['file_spdx_tag']),
24+
','.join(license_w_source['file_header']),
25+
','.join(license_w_source['license_file']),
26+
','.join(license_w_source['scancode']),
27+
scan_item.matched_lines, scan_item.fileURL]
28+
scanoss_extra_info.append(extra_item)
29+
scanoss_extra_info.insert(0, SCANOSS_INFO_HEADER)
30+
return scanoss_extra_info
1231

1332

1433
def parsing_scanResult(scanoss_report):
@@ -21,39 +40,43 @@ def parsing_scanResult(scanoss_report):
2140
continue
2241

2342
if 'component' in findings[0]:
24-
result_item.set_oss_name(findings[0]['component'])
43+
result_item.oss_name = findings[0]['component']
2544
if 'version' in findings[0]:
26-
result_item.set_oss_version(findings[0]['version'])
45+
result_item.oss_version = findings[0]['version']
2746
if 'url' in findings[0]:
28-
result_item.set_download_location(findings[0]['url'])
47+
result_item.download_location = findings[0]['url']
2948

3049
license_detected = []
50+
license_w_source = {"component_declared": [], "file_spdx_tag": [],
51+
"file_header": [], "license_file": [], "scancode": []}
3152
copyright_detected = []
3253
if 'licenses' in findings[0]:
3354
for license in findings[0]['licenses']:
3455
license_detected.append(license['name'].lower())
56+
if license['source'] not in license_w_source:
57+
license_w_source[license['source']] = []
58+
license_w_source[license['source']].append(license['name'])
3559
if len(license_detected) > 0:
36-
result_item.set_licenses(license_detected)
60+
result_item.licenses = license_detected
61+
result_item.scanoss_reference = license_w_source
3762
if 'copyrights' in findings[0]:
3863
for copyright in findings[0]['copyrights']:
3964
copyright_detected.append(copyright['name'])
4065
if len(copyright_detected) > 0:
41-
result_item.set_copyright(copyright_detected)
66+
result_item.copyright = copyright_detected
4267

4368
if is_exclude_file(file_path):
44-
result_item.set_exclude(True)
69+
result_item.exclude = True
4570

46-
if 'vendor' in findings[0]:
47-
result_item.set_vendor(findings[0]['vendor'])
4871
if 'file_url' in findings[0]:
49-
result_item.set_fileURL(findings[0]['file_url'])
72+
result_item.fileURL = findings[0]['file_url']
5073
if 'matched' in findings[0]:
5174
if 'lines' in findings[0]:
52-
result_item.set_matched_lines(f"{findings[0]['matched']} ({findings[0]['lines']})")
75+
result_item.matched_lines = f"{findings[0]['matched']} ({findings[0]['lines']})"
5376
else:
54-
result_item.set_matched_lines(f"{findings[0]['matched']}")
77+
result_item.matched_lines = f"{findings[0]['matched']}"
5578
elif 'lines' in findings[0]:
56-
result_item.set_matched_lines(f"({findings[0]['lines']})")
79+
result_item.matched_lines = f"({findings[0]['lines']})"
5780

5881
scanoss_file_item.append(result_item)
5982

src/fosslight_source/_scan_item.py

Lines changed: 23 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -22,71 +22,46 @@
2222

2323
class ScanItem:
2424
file = ""
25-
licenses = []
26-
copyright = ""
25+
scanoss_reference = {}
2726
exclude = False
2827
is_license_text = False
2928
oss_name = ""
3029
oss_version = ""
3130
download_location = ""
3231
matched_lines = ""
3332
fileURL = ""
34-
vendor = ""
3533
license_reference = ""
3634

3735
def __init__(self, value):
3836
self.file = value
39-
self.copyright = []
40-
self.licenses = []
37+
self._copyright = []
38+
self._licenses = []
4139
self.comment = ""
4240
self.exclude = False
4341
self.is_license_text = False
4442

4543
def __del__(self):
4644
pass
4745

48-
def set_comment(self, value):
49-
self.comment = value
46+
@property
47+
def copyright(self):
48+
return self._copyright
5049

51-
def set_file(self, value):
52-
self.file = value
53-
54-
def set_copyright(self, value):
55-
self.copyright.extend(value)
56-
if len(self.copyright) > 0:
57-
self.copyright = list(set(self.copyright))
58-
59-
def set_licenses(self, value):
60-
self.licenses.extend(value)
61-
if len(self.licenses) > 0:
62-
self.licenses = list(set(self.licenses))
63-
64-
def set_exclude(self, value):
65-
self.exclude = value
66-
67-
def set_is_license_text(self, value):
68-
self.is_license_text = value
50+
@copyright.setter
51+
def copyright(self, value):
52+
self._copyright.extend(value)
53+
if len(self._copyright) > 0:
54+
self._copyright = list(set(self._copyright))
6955

70-
def set_oss_name(self, value):
71-
self.oss_name = value
56+
@property
57+
def licenses(self):
58+
return self._licenses
7259

73-
def set_oss_version(self, value):
74-
self.oss_version = value
75-
76-
def set_download_location(self, value):
77-
self.download_location = value
78-
79-
def set_matched_lines(self, value):
80-
self.matched_lines = value
81-
82-
def set_fileURL(self, value):
83-
self.fileURL = value
84-
85-
def set_vendor(self, value):
86-
self.vendor = value
87-
88-
def set_license_reference(self, value):
89-
self.license_reference = value
60+
@licenses.setter
61+
def licenses(self, value):
62+
self._licenses.extend(value)
63+
if len(self._licenses) > 0:
64+
self._licenses = list(set(self._licenses))
9065

9166
def get_row_to_print(self):
9267
print_rows = [self.file, self.oss_name, self.oss_version, ','.join(self.licenses), self.download_location, "",
@@ -98,15 +73,13 @@ def get_row_to_print(self):
9873
def get_row_to_print_for_scanoss(self):
9974
print_rows = [self.file, self.oss_name, self.oss_version, ','.join(self.licenses), self.download_location, "",
10075
','.join(self.copyright),
101-
"Exclude" if self.exclude else "",
102-
self.comment, self.matched_lines, self.fileURL, self.vendor]
76+
"Exclude" if self.exclude else "", self.comment]
10377
return print_rows
10478

10579
def get_row_to_print_for_all_scanner(self):
10680
print_rows = [self.file, self.oss_name, self.oss_version, ','.join(self.licenses), self.download_location, "",
10781
','.join(self.copyright),
108-
"Exclude" if self.exclude else "",
109-
self.comment, self.license_reference, self.matched_lines, self.fileURL, self.vendor]
82+
"Exclude" if self.exclude else "", self.comment, self.license_reference]
11083
return print_rows
11184

11285
def merge_scan_item(self, other):
@@ -136,8 +109,8 @@ def merge_scan_item(self, other):
136109
self.matched_lines = other.matched_lines
137110
if not self.fileURL:
138111
self.fileURL = other.fileURL
139-
if not self.vendor:
140-
self.vendor = other.vendor
112+
if not self.scanoss_reference:
113+
self.scanoss_reference = other.scanoss_reference
141114

142115
def __eq__(self, other):
143116
return self.file == other.file

src/fosslight_source/cli.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,17 @@
1818
from fosslight_util.output_format import check_output_format, write_output_file
1919
from .run_scancode import run_scan
2020
from .run_scanoss import run_scanoss_py
21+
from .run_scanoss import get_scanoss_extra_info
2122

2223
SCANOSS_SHEET_NAME = 'SRC_FL_Source'
2324
SCANOSS_HEADER = {SCANOSS_SHEET_NAME: ['ID', 'Source Name or Path', 'OSS Name',
2425
'OSS Version', 'License', 'Download Location',
2526
'Homepage', 'Copyright Text', 'Exclude',
26-
'Comment', 'scanoss_matched_lines',
27-
'scanoss_fileURL', 'scanoss_vendor']}
27+
'Comment']}
2828
MERGED_HEADER = {SCANOSS_SHEET_NAME: ['ID', 'Source Name or Path', 'OSS Name',
2929
'OSS Version', 'License', 'Download Location',
3030
'Homepage', 'Copyright Text', 'Exclude',
31-
'Comment', 'license_reference', 'scanoss_matched_lines',
32-
'scanoss_fileURL', 'scanoss_vendor']}
31+
'Comment', 'license_reference']}
3332

3433
logger = logging.getLogger(constant.LOGGER_NAME)
3534
warnings.filterwarnings("ignore", category=FutureWarning)
@@ -142,7 +141,13 @@ def create_report_file(start_time, scanned_result, license_list, selected_scanne
142141
extended_header = MERGED_HEADER
143142

144143
if need_license:
145-
sheet_list["matched_text"] = get_license_list_to_print(license_list)
144+
if selected_scanner == 'scancode' or output_extension == _json_ext:
145+
sheet_list["scancode_reference"] = get_license_list_to_print(license_list)
146+
elif selected_scanner == 'scanoss':
147+
sheet_list["scanoss_reference"] = get_scanoss_extra_info(scanned_result)
148+
else:
149+
sheet_list["scancode_reference"] = get_license_list_to_print(license_list)
150+
sheet_list["scanoss_reference"] = get_scanoss_extra_info(scanned_result)
146151

147152
output_file_without_ext = os.path.join(output_path, output_file)
148153
success_to_write, writing_msg, result_file = write_output_file(output_file_without_ext, output_extension,

src/fosslight_source/run_scanoss.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from fosslight_util.set_log import init_log
1414
from fosslight_util.output_format import check_output_format # , write_output_file
1515
from ._parsing_scanoss_file import parsing_scanResult # scanoss
16+
from ._parsing_scanoss_file import parsing_extraInfo # scanoss
1617
import shutil
1718
from pathlib import Path
1819

@@ -24,6 +25,10 @@
2425
SCANOSS_COMMAND_PREFIX = "scanoss-py scan -o "
2526

2627

28+
def get_scanoss_extra_info(scanned_result):
29+
return parsing_extraInfo(scanned_result)
30+
31+
2732
def run_scanoss_py(path_to_scan, output_file_name="", format="", called_by_cli=False, write_json_file=False, num_threads=-1):
2833
"""
2934
Run scanoss.py for the given path.

0 commit comments

Comments
 (0)