Skip to content

Commit 49ac4b1

Browse files
committed
Add variable to check binary
1 parent 8881feb commit 49ac4b1

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

src/fosslight_util/oss_item.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ def __init__(self, value):
2424
self.download_location = ""
2525
self._yocto_recipe = []
2626
self._yocto_package = []
27+
self.is_binary = False
2728

2829
def __del__(self):
2930
pass

src/fosslight_util/read_excel.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@
1111

1212
logger = logging.getLogger(LOGGER_NAME)
1313
IDX_CANNOT_FOUND = -1
14+
PREFIX_BIN = "bin"
1415

1516

1617
def read_oss_report(excel_file, sheet_names=""):
1718
_oss_report_items = []
18-
_xl_sheets = []
19+
xl_sheets = {}
1920
all_sheet_to_read = []
2021
not_matched_sheet = []
2122
any_sheet_matched = False
@@ -44,7 +45,7 @@ def read_oss_report(excel_file, sheet_names=""):
4445
sheet = xl_workbook.sheet_by_name(sheet_name)
4546
if sheet:
4647
logger.info(f"Load a matched sheet: {sheet_name}")
47-
_xl_sheets.append(sheet)
48+
xl_sheets[sheet_name] = sheet
4849
any_sheet_matched = True
4950
if not any_sheet_matched:
5051
not_matched_sheet.append(sheet_to_read)
@@ -58,7 +59,7 @@ def read_oss_report(excel_file, sheet_names=""):
5859
elif (not sheet_name_prefix_match) and not_matched_sheet:
5960
logger.warning(f"Not matched sheet name: {not_matched_sheet}")
6061

61-
for xl_sheet in _xl_sheets:
62+
for sheet_name, xl_sheet in xl_sheets.items():
6263
_item_idx = {
6364
"ID": IDX_CANNOT_FOUND,
6465
"Source Name or Path": IDX_CANNOT_FOUND,
@@ -90,8 +91,11 @@ def read_oss_report(excel_file, sheet_names=""):
9091
# Get all values, iterating through rows and columns
9192
column_keys = json.loads(json.dumps(_item_idx))
9293

94+
is_bin = True if sheet_name.lower().startswith(PREFIX_BIN) else False
95+
9396
for row_idx in range(DATA_START_ROW_IDX, xl_sheet.nrows):
9497
item = OssItem("")
98+
item.is_binary = is_bin
9599
valid_row = True
96100
load_data_cnt = 0
97101

src/fosslight_util/write_scancodejson.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def write_scancodejson(output_dir, output_filename, oss_list):
3131
else:
3232
json_output['files'] = add_item_in_files(oi, item_path, json_output['files'])
3333
with open(os.path.join(output_dir, output_filename), 'w') as f:
34-
json.dump(json_output, f, sort_keys=False)
34+
json.dump(json_output, f, sort_keys=False, indent=4)
3535

3636

3737
def append_oss_item_in_filesitem(item, files_item):
@@ -42,6 +42,8 @@ def append_oss_item_in_filesitem(item, files_item):
4242
oss_item['copyright'] = item.copyright
4343
oss_item['download_location'] = item.download_location
4444
oss_item['comment'] = item.comment
45+
if item.is_binary:
46+
files_item['is_binary'] = item.is_binary
4547
files_item['oss'].append(oss_item)
4648
return files_item
4749

@@ -50,6 +52,7 @@ def add_item_in_files(item, item_path, files_list):
5052
files_item = {}
5153
files_item['path'] = item_path
5254
files_item['name'] = os.path.basename(item_path)
55+
files_item['is_binary'] = item.is_binary
5356
files_item['base_name'], files_item['extension'] = os.path.splitext(os.path.basename(item_path))
5457
files_item['oss'] = []
5558
files_item = append_oss_item_in_filesitem(item, files_item)

0 commit comments

Comments
 (0)