diff --git a/src/fosslight_util/oss_item.py b/src/fosslight_util/oss_item.py index 94e9811..355dd13 100644 --- a/src/fosslight_util/oss_item.py +++ b/src/fosslight_util/oss_item.py @@ -24,6 +24,7 @@ def __init__(self, value): self.download_location = "" self._yocto_recipe = [] self._yocto_package = [] + self.is_binary = False def __del__(self): pass diff --git a/src/fosslight_util/read_excel.py b/src/fosslight_util/read_excel.py index a436dd8..d537afd 100644 --- a/src/fosslight_util/read_excel.py +++ b/src/fosslight_util/read_excel.py @@ -11,11 +11,12 @@ logger = logging.getLogger(LOGGER_NAME) IDX_CANNOT_FOUND = -1 +PREFIX_BIN = "bin" def read_oss_report(excel_file, sheet_names=""): _oss_report_items = [] - _xl_sheets = [] + xl_sheets = {} all_sheet_to_read = [] not_matched_sheet = [] any_sheet_matched = False @@ -44,7 +45,7 @@ def read_oss_report(excel_file, sheet_names=""): sheet = xl_workbook.sheet_by_name(sheet_name) if sheet: logger.info(f"Load a matched sheet: {sheet_name}") - _xl_sheets.append(sheet) + xl_sheets[sheet_name] = sheet any_sheet_matched = True if not any_sheet_matched: not_matched_sheet.append(sheet_to_read) @@ -58,7 +59,7 @@ def read_oss_report(excel_file, sheet_names=""): elif (not sheet_name_prefix_match) and not_matched_sheet: logger.warning(f"Not matched sheet name: {not_matched_sheet}") - for xl_sheet in _xl_sheets: + for sheet_name, xl_sheet in xl_sheets.items(): _item_idx = { "ID": IDX_CANNOT_FOUND, "Source Name or Path": IDX_CANNOT_FOUND, @@ -90,8 +91,11 @@ def read_oss_report(excel_file, sheet_names=""): # Get all values, iterating through rows and columns column_keys = json.loads(json.dumps(_item_idx)) + is_bin = True if sheet_name.lower().startswith(PREFIX_BIN) else False + for row_idx in range(DATA_START_ROW_IDX, xl_sheet.nrows): item = OssItem("") + item.is_binary = is_bin valid_row = True load_data_cnt = 0 diff --git a/src/fosslight_util/write_scancodejson.py b/src/fosslight_util/write_scancodejson.py index 05228d3..1123f70 100644 --- a/src/fosslight_util/write_scancodejson.py +++ b/src/fosslight_util/write_scancodejson.py @@ -31,7 +31,7 @@ def write_scancodejson(output_dir, output_filename, oss_list): else: json_output['files'] = add_item_in_files(oi, item_path, json_output['files']) with open(os.path.join(output_dir, output_filename), 'w') as f: - json.dump(json_output, f, sort_keys=False) + json.dump(json_output, f, sort_keys=False, indent=4) def append_oss_item_in_filesitem(item, files_item): @@ -42,6 +42,8 @@ def append_oss_item_in_filesitem(item, files_item): oss_item['copyright'] = item.copyright oss_item['download_location'] = item.download_location oss_item['comment'] = item.comment + if item.is_binary: + files_item['is_binary'] = item.is_binary files_item['oss'].append(oss_item) return files_item @@ -50,6 +52,7 @@ def add_item_in_files(item, item_path, files_list): files_item = {} files_item['path'] = item_path files_item['name'] = os.path.basename(item_path) + files_item['is_binary'] = item.is_binary files_item['base_name'], files_item['extension'] = os.path.splitext(os.path.basename(item_path)) files_item['oss'] = [] files_item = append_oss_item_in_filesitem(item, files_item)