Skip to content

Commit 68a3d64

Browse files
Add license reference column (#59)
Add warning message to notify requirements Co-authored-by: Wonjae Park <[email protected]>
1 parent 668055e commit 68a3d64

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

src/fosslight_source/_scan_item.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class ScanItem:
3232
matched_lines = ""
3333
fileURL = ""
3434
vendor = ""
35+
license_reference = ""
3536

3637
def __init__(self, value):
3738
self.file = value
@@ -84,6 +85,9 @@ def set_fileURL(self, value):
8485
def set_vendor(self, value):
8586
self.vendor = value
8687

88+
def set_license_reference(self, value):
89+
self.license_reference = value
90+
8791
def get_row_to_print(self):
8892
print_rows = [self.file, self.oss_name, self.oss_version, ','.join(self.licenses), self.download_location, "",
8993
','.join(self.copyright),
@@ -98,12 +102,20 @@ def get_row_to_print_for_scanoss(self):
98102
self.comment, self.matched_lines, self.fileURL, self.vendor]
99103
return print_rows
100104

105+
def get_row_to_print_for_all_scanner(self):
106+
print_rows = [self.file, self.oss_name, self.oss_version, ','.join(self.licenses), self.download_location, "",
107+
','.join(self.copyright),
108+
"Exclude" if self.exclude else "",
109+
self.comment, self.license_reference, self.matched_lines, self.fileURL, self.vendor]
110+
return print_rows
111+
101112
def merge_scan_item(self, other):
102113
"""
103114
Merge two ScanItem instance into one.
104-
105-
TODO: define how to merge comments and implement.
106115
"""
116+
if sorted(self.licenses) != sorted(other.licenses):
117+
self.license_reference = f"(Scancode) {', '.join(self.licenses)} / (Scanoss) {', '.join(other.licenses)}"
118+
107119
self.licenses = list(set(self.licenses + other.licenses))
108120

109121
if len(self.copyright) > 0:

src/fosslight_source/cli.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@
2525
'Homepage', 'Copyright Text', 'Exclude',
2626
'Comment', 'scanoss_matched_lines',
2727
'scanoss_fileURL', 'scanoss_vendor']}
28+
MERGED_HEADER = {SCANOSS_SHEET_NAME: ['ID', 'Source Name or Path', 'OSS Name',
29+
'OSS Version', 'License', 'Download Location',
30+
'Homepage', 'Copyright Text', 'Exclude',
31+
'Comment', 'license_reference', 'scanoss_matched_lines',
32+
'scanoss_fileURL', 'scanoss_vendor']}
2833

2934
logger = logging.getLogger(constant.LOGGER_NAME)
3035
warnings.filterwarnings("ignore", category=FutureWarning)
@@ -126,10 +131,14 @@ def create_report_file(start_time, scanned_result, license_list, selected_scanne
126131
if selected_scanner == 'scancode' or output_extension == _json_ext:
127132
sheet_list[SCANOSS_SHEET_NAME] = [scan_item.get_row_to_print() for scan_item in scanned_result]
128133

129-
else:
134+
elif selected_scanner == 'scanoss':
130135
sheet_list[SCANOSS_SHEET_NAME] = [scan_item.get_row_to_print_for_scanoss() for scan_item in scanned_result]
131136
extended_header = SCANOSS_HEADER
132137

138+
else:
139+
sheet_list[SCANOSS_SHEET_NAME] = [scan_item.get_row_to_print_for_all_scanner() for scan_item in scanned_result]
140+
extended_header = MERGED_HEADER
141+
133142
if need_license:
134143
sheet_list["matched_text"] = get_license_list_to_print(license_list)
135144

src/fosslight_source/run_scanoss.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ def run_scanoss_py(path_to_scan, output_file_name="", format="", called_by_cli=F
3939
pkg_resources.get_distribution("scanoss")
4040
except Exception as error:
4141
logger.warning(str(error) + ". Skipping scan with scanoss.")
42+
logger.warning("Please install scanoss and dataclasses before run fosslight_source with scanoss option.")
4243
return scanoss_file_list
4344
scan_command = "scanoss-py scan -o "
4445

0 commit comments

Comments
 (0)