Skip to content

Commit

Permalink
Fix the issue for correct mode (#123)
Browse files Browse the repository at this point in the history
* Fix to maintain exclude value for sbom-info.yaml
* Modify to sort the excel, csv result
 - 1st: exclude
 - 2nd: source name or path is empty
 - 3rd: source name or path
* Fix the issue about sbom-info.yaml
* Fix the magic number


---------

Signed-off-by: Jiyeong Seok <[email protected]>
  • Loading branch information
dd-jy authored Jul 14, 2023
1 parent 43c1629 commit 45e2763
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/fosslight_util/correct.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ def correct_with_yaml(correct_filepath, path_to_scan, scanner_oss_list):
return success, msg, correct_list

rel_path = os.path.relpath(path_to_scan, correct_filepath)
rel_correct_path = os.path.relpath(correct_filepath, path_to_scan)

yaml_oss_list, _, err_msg = parsing_yml(correct_yaml, os.path.dirname(correct_yaml), print_log=True)

Expand Down Expand Up @@ -73,8 +72,6 @@ def correct_with_yaml(correct_filepath, path_to_scan, scanner_oss_list):
if len(matched_yi) > 0:
for matched_yi_item in matched_yi:
matched_oss_item = copy.deepcopy(matched_yi_item)
if oss_item.exclude:
matched_oss_item.exclude = oss_item.exclude
if matched_oss_item.comment:
matched_oss_item.comment += '/'
matched_oss_item.comment += 'Loaded from sbom-info.yaml'
Expand All @@ -89,25 +86,28 @@ def correct_with_yaml(correct_filepath, path_to_scan, scanner_oss_list):
if sheet_name == 'SRC_FL_Source':
for n_idx, ni in enumerate(matched_yaml):
y_item = copy.deepcopy(yaml_oss_list[n_idx])
all_matched = False
if sum(ni) != 0:
not_matched_path = []
for idx, id in enumerate(ni):
if not id:
not_matched_path.append(y_item.source_name_or_path[idx])
y_item.source_name_or_path = []
y_item.source_name_or_path = not_matched_path
if len(not_matched_path) == 0:
all_matched = True
if y_item.comment:
y_item.comment += '/'
y_item.comment += 'Added by sbom-info.yaml'
if not y_item.source_name_or_path:
if not (y_item.source_name_or_path or all_matched):
correct_contents.append(y_item.get_print_array()[0])
continue
for y_path in y_item.source_name_or_path:
y_item_i = copy.deepcopy(y_item)
if not os.path.exists(os.path.normpath(os.path.join(correct_filepath, y_path))):
y_item_i.exclude = True
y_item_i.source_name_or_path = []
y_item_i.source_name_or_path = os.path.join(rel_correct_path, y_path)
y_item_i.source_name_or_path = y_path
correct_contents.append(y_item_i.get_print_array()[0])
correct_list[sheet_name] = correct_contents

Expand Down
6 changes: 6 additions & 0 deletions src/fosslight_util/write_excel.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
_OUTPUT_FILE_PREFIX = "FOSSLight-Report_"
_EMPTY_ITEM_MSG = "* There is no item"\
" to print in FOSSLight-Report.\n"
IDX_FILE = 0
IDX_EXCLUDE = 7
logger = logging.getLogger(constant.LOGGER_NAME)


Expand Down Expand Up @@ -137,6 +139,8 @@ def write_result_to_csv(output_file, sheet_list_origin, separate_sheet=False, ex
else:
output_file = separate_output_file + "_" + sheet_name + file_extension

sheet_content_without_header = sorted(sheet_content_without_header,
key=lambda x: (x[IDX_EXCLUDE], x[IDX_FILE] == "", x[IDX_FILE]))
with open(output_file, 'w', newline='') as file:
writer = csv.writer(file, delimiter='\t')
writer.writerow(header_row)
Expand Down Expand Up @@ -166,6 +170,8 @@ def write_result_to_excel(out_file_name, sheet_list, extended_header={}):
workbook = xlsxwriter.Workbook(out_file_name)
for sheet_name, sheet_contents in sheet_list.items():
selected_header, sheet_content_without_header = get_header_row(sheet_name, sheet_contents[:], extended_header)
sheet_content_without_header = sorted(sheet_content_without_header,
key=lambda x: (x[IDX_EXCLUDE], x[IDX_FILE] == "", x[IDX_FILE]))
worksheet = create_worksheet(workbook, sheet_name, selected_header)
write_result_to_sheet(worksheet, sheet_content_without_header)
workbook.close()
Expand Down

0 comments on commit 45e2763

Please sign in to comment.