Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 20 additions & 13 deletions src/fosslight_source/_scan_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ class ScanItem:
oss_name = ""
oss_version = ""
download_location = ""
matched_lines = "" # for scanoss
fileURL = "" # for scanoss
vendor = "" # for scanoss
matched_lines = ""
fileURL = ""
vendor = ""

def __init__(self, value):
self.file = value
Expand Down Expand Up @@ -85,16 +85,17 @@ def set_vendor(self, value):
self.vendor = value

def get_row_to_print(self):
if not self.download_location:
print_rows = [self.file, "", "", ','.join(self.licenses), "", "",
','.join(self.copyright),
"Exclude" if self.exclude else "",
self.comment]
else:
print_rows = [self.file, self.oss_name, self.oss_version, ','.join(self.licenses), self.download_location, "",
','.join(self.copyright),
"Exclude" if self.exclude else "",
self.comment]
print_rows = [self.file, self.oss_name, self.oss_version, ','.join(self.licenses), self.download_location, "",
','.join(self.copyright),
"Exclude" if self.exclude else "",
self.comment]
return print_rows

def get_row_to_print_for_scanoss(self):
print_rows = [self.file, self.oss_name, self.oss_version, ','.join(self.licenses), self.download_location, "",
','.join(self.copyright),
"Exclude" if self.exclude else "",
self.comment, self.matched_lines, self.fileURL, self.vendor]
return print_rows

def merge_scan_item(self, other):
Expand All @@ -119,6 +120,12 @@ def merge_scan_item(self, other):
self.oss_version = other.oss_version
if not self.download_location:
self.download_location = other.download_location
if not self.matched_lines:
self.matched_lines = other.matched_lines
if not self.fileURL:
self.fileURL = other.fileURL
if not self.vendor:
self.vendor = other.vendor

def __eq__(self, other):
return self.file == other.file
Expand Down
23 changes: 19 additions & 4 deletions src/fosslight_source/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@
from .run_scancode import run_scan
from .run_scanoss import run_scanoss_py

SCANOSS_SHEET_NAME = 'SRC_FL_Source'
SCANOSS_HEADER = {SCANOSS_SHEET_NAME: ['ID', 'Source Name or Path', 'OSS Name',
'OSS Version', 'License', 'Download Location',
'Homepage', 'Copyright Text', 'Exclude',
'Comment', 'scanoss_matched_lines',
'scanoss_fileURL', 'scanoss_vendor']}

logger = logging.getLogger(constant.LOGGER_NAME)
warnings.filterwarnings("ignore", category=FutureWarning)
_PKG_NAME = "fosslight_source"
Expand Down Expand Up @@ -82,10 +89,11 @@ def main():
else:
print_help_msg_source()
sys.exit(1)
create_report_file(start_time, scanned_result, license_list, print_matched_text, output_path, output_file, output_extension)
create_report_file(start_time, scanned_result, license_list, selected_scanner, print_matched_text,
output_path, output_file, output_extension)


def create_report_file(start_time, scanned_result, license_list, need_license=False,
def create_report_file(start_time, scanned_result, license_list, selected_scanner, need_license=False,
output_path="", output_file="", output_extension=""):
"""
Create report files for given scanned result.
Expand All @@ -95,6 +103,7 @@ def create_report_file(start_time, scanned_result, license_list, need_license=Fa
:param license_list: matched text (only for scancode).
:param need_license: if requested, output matched text (only for scancode).
"""
extended_header = {}
_result_log = {}
sheet_list = {}
_json_ext = ".json"
Expand All @@ -111,13 +120,19 @@ def create_report_file(start_time, scanned_result, license_list, need_license=Fa
output_file = "FOSSLight-Report_" + start_time

scanned_result = sorted(scanned_result, key=lambda row: (''.join(row.licenses)))
sheet_list["SRC_FL_Source"] = [scan_item.get_row_to_print() for scan_item in scanned_result]

if selected_scanner == 'scancode' or output_extension == _json_ext:
sheet_list[SCANOSS_SHEET_NAME] = [scan_item.get_row_to_print() for scan_item in scanned_result]

else:
sheet_list[SCANOSS_SHEET_NAME] = [scan_item.get_row_to_print_for_scanoss() for scan_item in scanned_result]
extended_header = SCANOSS_HEADER

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

output_file_without_ext = os.path.join(output_path, output_file)
success_to_write, writing_msg = write_output_file(output_file_without_ext, output_extension, sheet_list)
success_to_write, writing_msg = write_output_file(output_file_without_ext, output_extension, sheet_list, extended_header)
logger.info("Writing Output file(" + output_file + output_extension + "):"
+ str(success_to_write) + " " + writing_msg)
if success_to_write:
Expand Down