Skip to content

Commit

Permalink
Fix not to create csv if format is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
dd-jy authored Jul 20, 2022
1 parent 8dededc commit 55ef9a7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 14 deletions.
8 changes: 4 additions & 4 deletions src/fosslight_util/output_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Copyright (c) 2021 LG Electronics Inc.
# SPDX-License-Identifier: Apache-2.0
import os
from fosslight_util.write_excel import write_result_to_excel, write_excel_and_csv, write_result_to_csv
from fosslight_util.write_excel import write_result_to_excel, write_result_to_csv
from fosslight_util.write_opossum import write_opossum
from fosslight_util.write_yaml import write_yaml

Expand Down Expand Up @@ -62,11 +62,11 @@ def check_output_format(output='', format='', customized_format={}):
def write_output_file(output_file_without_ext, file_extension, sheet_list, extended_header={}):
success = True
msg = ''
if file_extension == '':
file_extension = '.xlsx'
result_file = output_file_without_ext + file_extension

if file_extension == '':
success, msg, result_file = write_excel_and_csv(output_file_without_ext, sheet_list, False, extended_header)
elif file_extension == '.xlsx':
if file_extension == '.xlsx':
success, msg = write_result_to_excel(result_file, sheet_list, extended_header)
elif file_extension == '.csv':
success, msg, result_file = write_result_to_csv(result_file, sheet_list)
Expand Down
12 changes: 2 additions & 10 deletions src/fosslight_util/write_excel.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,15 +196,13 @@ def create_worksheet(workbook, sheet_name, header_row):
return worksheet


def merge_excels(find_excel_dir, final_out, csv=True):
def merge_excels(find_excel_dir, final_out):
success = True
msg = ""
output_files = []
FIND_EXTENSION = '.xlsx'
added_sheet_names = []
try:
files = os.listdir(find_excel_dir)
out_dir = os.path.dirname(final_out)

if len([name for name in files if name.endswith(FIND_EXTENSION)]) > 0:
writer = pd.ExcelWriter(final_out)
Expand All @@ -220,19 +218,13 @@ def merge_excels(find_excel_dir, final_out, csv=True):
sheet_name_to_copy = f"{f_short_name}_{sheet_name}"
df_excel = pd.read_excel(
file, sheet_name=sheet_name, engine='openpyxl')
if csv:
csv_file = os.path.join(out_dir, f"{sheet_name_to_copy}.csv")
df_excel.to_csv(csv_file, index=False)
output_files.append(csv_file)
if sheet_name not in added_sheet_names:
sheet_name_to_copy = sheet_name
df_excel.to_excel(writer, sheet_name_to_copy,
index=False)
writer.save()
output_files.append(final_out)
except Exception as ex:
msg = str(ex)
success = False
if success:
msg = ",".join(output_files)

return success, msg

0 comments on commit 55ef9a7

Please sign in to comment.