Skip to content

Commit 9dd42f0

Browse files
JustinWonjaeParksoimkim
authored andcommitted
Add scanoss information on excel
1 parent 7358147 commit 9dd42f0

File tree

2 files changed

+39
-17
lines changed

2 files changed

+39
-17
lines changed

src/fosslight_source/_scan_item.py

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ class ScanItem:
2929
oss_name = ""
3030
oss_version = ""
3131
download_location = ""
32-
matched_lines = "" # for scanoss
33-
fileURL = "" # for scanoss
34-
vendor = "" # for scanoss
32+
matched_lines = ""
33+
fileURL = ""
34+
vendor = ""
3535

3636
def __init__(self, value):
3737
self.file = value
@@ -85,16 +85,17 @@ def set_vendor(self, value):
8585
self.vendor = value
8686

8787
def get_row_to_print(self):
88-
if not self.download_location:
89-
print_rows = [self.file, "", "", ','.join(self.licenses), "", "",
90-
','.join(self.copyright),
91-
"Exclude" if self.exclude else "",
92-
self.comment]
93-
else:
94-
print_rows = [self.file, self.oss_name, self.oss_version, ','.join(self.licenses), self.download_location, "",
95-
','.join(self.copyright),
96-
"Exclude" if self.exclude else "",
97-
self.comment]
88+
print_rows = [self.file, self.oss_name, self.oss_version, ','.join(self.licenses), self.download_location, "",
89+
','.join(self.copyright),
90+
"Exclude" if self.exclude else "",
91+
self.comment]
92+
return print_rows
93+
94+
def get_row_to_print_for_scanoss(self):
95+
print_rows = [self.file, self.oss_name, self.oss_version, ','.join(self.licenses), self.download_location, "",
96+
','.join(self.copyright),
97+
"Exclude" if self.exclude else "",
98+
self.comment, self.matched_lines, self.fileURL, self.vendor]
9899
return print_rows
99100

100101
def merge_scan_item(self, other):
@@ -119,6 +120,12 @@ def merge_scan_item(self, other):
119120
self.oss_version = other.oss_version
120121
if not self.download_location:
121122
self.download_location = other.download_location
123+
if not self.matched_lines:
124+
self.matched_lines = other.matched_lines
125+
if not self.fileURL:
126+
self.fileURL = other.fileURL
127+
if not self.vendor:
128+
self.vendor = other.vendor
122129

123130
def __eq__(self, other):
124131
return self.file == other.file

src/fosslight_source/cli.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@
1919
from .run_scancode import run_scan
2020
from .run_scanoss import run_scanoss_py
2121

22+
SCANOSS_SHEET_NAME = 'SRC_FL_Source'
23+
SCANOSS_HEADER = {SCANOSS_SHEET_NAME: ['ID', 'Source Name or Path', 'OSS Name',
24+
'OSS Version', 'License', 'Download Location',
25+
'Homepage', 'Copyright Text', 'Exclude',
26+
'Comment', 'scanoss_matched_lines',
27+
'scanoss_fileURL', 'scanoss_vendor']}
28+
2229
logger = logging.getLogger(constant.LOGGER_NAME)
2330
warnings.filterwarnings("ignore", category=FutureWarning)
2431
_PKG_NAME = "fosslight_source"
@@ -82,10 +89,11 @@ def main():
8289
else:
8390
print_help_msg_source()
8491
sys.exit(1)
85-
create_report_file(start_time, scanned_result, license_list, print_matched_text, output_path, output_file, output_extension)
92+
create_report_file(start_time, scanned_result, license_list, selected_scanner, print_matched_text,
93+
output_path, output_file, output_extension)
8694

8795

88-
def create_report_file(start_time, scanned_result, license_list, need_license=False,
96+
def create_report_file(start_time, scanned_result, license_list, selected_scanner, need_license=False,
8997
output_path="", output_file="", output_extension=""):
9098
"""
9199
Create report files for given scanned result.
@@ -95,6 +103,7 @@ def create_report_file(start_time, scanned_result, license_list, need_license=Fa
95103
:param license_list: matched text (only for scancode).
96104
:param need_license: if requested, output matched text (only for scancode).
97105
"""
106+
extended_header = {}
98107
_result_log = {}
99108
sheet_list = {}
100109
_json_ext = ".json"
@@ -111,13 +120,19 @@ def create_report_file(start_time, scanned_result, license_list, need_license=Fa
111120
output_file = "FOSSLight-Report_" + start_time
112121

113122
scanned_result = sorted(scanned_result, key=lambda row: (''.join(row.licenses)))
114-
sheet_list["SRC_FL_Source"] = [scan_item.get_row_to_print() for scan_item in scanned_result]
123+
124+
if selected_scanner == 'scancode' or output_extension == _json_ext:
125+
sheet_list[SCANOSS_SHEET_NAME] = [scan_item.get_row_to_print() for scan_item in scanned_result]
126+
127+
else:
128+
sheet_list[SCANOSS_SHEET_NAME] = [scan_item.get_row_to_print_for_scanoss() for scan_item in scanned_result]
129+
extended_header = SCANOSS_HEADER
115130

116131
if need_license:
117132
sheet_list["matched_text"] = get_license_list_to_print(license_list)
118133

119134
output_file_without_ext = os.path.join(output_path, output_file)
120-
success_to_write, writing_msg = write_output_file(output_file_without_ext, output_extension, sheet_list)
135+
success_to_write, writing_msg = write_output_file(output_file_without_ext, output_extension, sheet_list, extended_header)
121136
logger.info("Writing Output file(" + output_file + output_extension + "):"
122137
+ str(success_to_write) + " " + writing_msg)
123138
if success_to_write:

0 commit comments

Comments
 (0)