Skip to content
Closed
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
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
commit = True
tag = False
message = Bump version: {current_version} → {new_version}
current_version = 1.3.5
current_version = 1.3.6

[bumpversion:file:setup.py]
search = '{current_version}'
Expand Down
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# Changelog

## v1.3.6 (18/11/2021)
## Changes
## 🐛 Hotfixes

- Fix bug in opossum exporter @nicarl (#37)

## 🔧 Maintenance

- Modify the tox issue @dd-jy (#41)
- Update spdx license list data v3.15 @dd-jy (#39)
- Exclude null fields from opossum export @nicarl (#38)

---

## v1.3.5 (28/10/2021)
## Changes
## 🔧 Maintenance
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
if __name__ == "__main__":
setup(
name='fosslight_util',
version='1.3.5',
version='1.3.6',
package_dir={"": "src"},
packages=find_packages(where='src'),
description='FOSSLight Util',
Expand Down
6 changes: 3 additions & 3 deletions src/fosslight_util/output_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@ def check_output_format(output='', format=''):
return success, msg, output_path, output_file, output_extension


def write_output_file(output_file_without_ext, file_extension, sheet_list):
def write_output_file(output_file_without_ext, file_extension, sheet_list, extended_header={}):
success = True
msg = ''

if file_extension == '':
success, msg = write_excel_and_csv(output_file_without_ext, sheet_list)
success, msg = write_excel_and_csv(output_file_without_ext, sheet_list, False, extended_header)
elif file_extension == '.xlsx':
success, msg = write_result_to_excel(output_file_without_ext + file_extension, sheet_list)
success, msg = write_result_to_excel(output_file_without_ext + file_extension, sheet_list, extended_header)
elif file_extension == '.csv':
success, msg = write_result_to_csv(output_file_without_ext + file_extension, sheet_list)
elif file_extension == '.json':
Expand Down
32 changes: 22 additions & 10 deletions src/fosslight_util/write_excel.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@
logger = logging.getLogger(constant.LOGGER_NAME)


def write_excel_and_csv(filename_without_extension, sheet_list, ignore_os=False):
# sheet_list = {} // Key = Sheet_name, Value = list of [row_items]
def write_excel_and_csv(filename_without_extension, sheet_list, ignore_os=False, extended_header={}):
success = True
error_msg = ""
success_csv = True
Expand All @@ -43,10 +42,11 @@ def write_excel_and_csv(filename_without_extension, sheet_list, ignore_os=False)
output_dir = os.path.dirname(filename_without_extension)
Path(output_dir).mkdir(parents=True, exist_ok=True)

success, error_msg = write_result_to_excel(filename_without_extension + ".xlsx", sheet_list)
success, error_msg = write_result_to_excel(filename_without_extension + ".xlsx", sheet_list, extended_header)

if ignore_os or platform.system() != "Windows":
success_csv, error_msg_csv = write_result_to_csv(filename_without_extension + ".csv", sheet_list, True)
success_csv, error_msg_csv = write_result_to_csv(filename_without_extension + ".csv",
sheet_list, True, extended_header)
if not success:
error_msg = "[Error] Writing excel:" + error_msg
if not success_csv:
Expand Down Expand Up @@ -82,18 +82,29 @@ def remove_empty_sheet(sheet_items):
return success, final_sheet_to_print


def get_header_row(sheet_name, sheet_content):
def get_header_row(sheet_name, sheet_content, extended_header):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's changeextended_headerto extended_header={}.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed as suggested.

selected_header = []

if extended_header:
for header_key in extended_header.keys():
_HEADER[header_key] = extended_header[header_key]

for header_key in _HEADER.keys():
if header_key in sheet_name:
if header_key == sheet_name:
selected_header = _HEADER[header_key]
break
if not selected_header:
for header_key in _HEADER.keys():
if sheet_name.startswith(header_key):
selected_header = _HEADER[header_key]
break

if len(selected_header) == 0:
selected_header = sheet_content.pop(0)
return selected_header, sheet_content


def write_result_to_csv(output_file, sheet_list_origin, separate_sheet=False):
def write_result_to_csv(output_file, sheet_list_origin, separate_sheet=False, extended_header={}):
success = True
error_msg = ""
file_extension = ".csv"
Expand All @@ -111,7 +122,7 @@ def write_result_to_csv(output_file, sheet_list_origin, separate_sheet=False):
merge_sheet = []
for sheet_name, sheet_contents in sheet_list.items():
row_num = 1
header_row, sheet_content_without_header = get_header_row(sheet_name, sheet_contents[:])
header_row, sheet_content_without_header = get_header_row(sheet_name, sheet_contents[:], extended_header)

if not separate_sheet:
merge_sheet.extend(sheet_content_without_header)
Expand All @@ -136,9 +147,10 @@ def write_result_to_csv(output_file, sheet_list_origin, separate_sheet=False):
return success, error_msg


def write_result_to_excel(out_file_name, sheet_list):
def write_result_to_excel(out_file_name, sheet_list, extended_header={}):
success = True
error_msg = ""

try:
is_not_null, sheet_list = remove_empty_sheet(sheet_list)
if is_not_null:
Expand All @@ -147,7 +159,7 @@ def write_result_to_excel(out_file_name, sheet_list):

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[:])
selected_header, sheet_content_without_header = get_header_row(sheet_name, sheet_contents[:], extended_header)
worksheet = create_worksheet(workbook, sheet_name, selected_header)
write_result_to_sheet(worksheet, sheet_content_without_header)
workbook.close()
Expand Down