Skip to content
Merged
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
3 changes: 2 additions & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ pytest
pytest-cov
pytest-flake8
flake8==3.9.2
fosslight-source
fosslight-source
spdx-tools==0.8.2
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ coloredlogs
python3-wget
beautifulsoup4
jsonmerge
spdx-tools==0.7.0rc0
spdx-tools
setuptools>=65.5.1 # not directly required, pinned by Snyk to avoid a vulnerability
numpy; python_version < '3.8'
numpy>=1.22.2; python_version >= '3.8'
Expand Down
2 changes: 2 additions & 0 deletions src/fosslight_util/oss_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from typing import List, Dict

_logger = logging.getLogger(LOGGER_NAME)
CHECKSUM_NULL = "0"


class OssItem:
Expand Down Expand Up @@ -98,6 +99,7 @@ def __init__(self, value):
self._comment = ""
self.is_binary = False
self.oss_items: List[OssItem] = []
self.checksum = CHECKSUM_NULL

def __del__(self):
pass
Expand Down
98 changes: 86 additions & 12 deletions src/fosslight_util/output_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@
# Copyright (c) 2021 LG Electronics Inc.
# SPDX-License-Identifier: Apache-2.0
import os
import platform
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
from fosslight_util.write_spdx import write_spdx
from typing import Tuple

SUPPORT_FORMAT = {'excel': '.xlsx', 'csv': '.csv', 'opossum': '.json', 'yaml': '.yaml'}
SUPPORT_FORMAT = {'excel': '.xlsx', 'csv': '.csv', 'opossum': '.json', 'yaml': '.yaml',
'spdx-yaml': '.yaml', 'spdx-json': '.json', 'spdx-xml': '.xml',
'spdx-tag': '.tag'}


def check_output_format(output='', format='', customized_format={}):
Expand Down Expand Up @@ -106,25 +110,95 @@ def check_output_formats(output='', formats=[], customized_format={}):
return success, msg, output_path, output_files, output_extensions


def check_output_formats_v2(output='', formats=[], customized_format={}):
success = True
msg = ''
output_path = ''
output_files = []
output_extensions = []

if customized_format:
support_format = customized_format
else:
support_format = SUPPORT_FORMAT

if formats:
# If -f option exist
formats = [format.lower() for format in formats]
for format in formats:
if format not in list(support_format.keys()):
success = False
msg = 'Enter the supported format with -f option: ' + ', '.join(list(support_format.keys()))
else:
output_extensions.append(support_format[format])

if success:
if output != '':
basename_extension = ''
if not os.path.isdir(output):
output_path = os.path.dirname(output)

basename = os.path.basename(output)
basename_file, basename_extension = os.path.splitext(basename)
if basename_extension:
if formats:
if basename_extension not in output_extensions:
success = False
msg = f"The format of output file(-o:'{output}') should be in the format list(-f:'{formats}')."
else:
if basename_extension not in support_format.values():
success = False
msg = 'Enter the supported file extension: ' + ', '.join(list(support_format.values()))
output_extensions.append(basename_extension)
output_files = [basename_file for _ in range(len(output_extensions))]
else:
output_path = output
if not output_extensions:
output_extensions = ['.xlsx']
if not formats:
for ext in output_extensions:
for key, value in support_format.items():
if value == ext:
formats.append(key)
break
return success, msg, output_path, output_files, output_extensions, formats


def write_output_file(output_file_without_ext: str, file_extension: str, scan_item, extended_header: dict = {},
hide_header: dict = {}) -> Tuple[bool, str, str]:
hide_header: dict = {}, format: str = '', spdx_version: str = '2.3') -> Tuple[bool, str, str]:
success = True
msg = ''

if file_extension == '':
file_extension = '.xlsx'
result_file = output_file_without_ext + file_extension

if file_extension == '.xlsx':
success, msg = write_result_to_excel(result_file, scan_item, extended_header, hide_header)
elif file_extension == '.csv':
success, msg, result_file = write_result_to_csv(result_file, scan_item, False, extended_header)
elif file_extension == '.json':
success, msg = write_opossum(result_file, scan_item)
elif file_extension == '.yaml':
success, msg, result_file = write_yaml(result_file, scan_item, False)
if format:
if format == 'excel':
success, msg = write_result_to_excel(result_file, scan_item, extended_header, hide_header)
elif format == 'csv':
success, msg, _ = write_result_to_csv(result_file, scan_item, False, extended_header)
elif format == 'opossum':
success, msg = write_opossum(result_file, scan_item)
elif format == 'yaml':
success, msg, _ = write_yaml(result_file, scan_item, False)
elif format.startswith('spdx'):
if platform.system() != 'Windows':
success, msg, _ = write_spdx(output_file_without_ext, file_extension, scan_item, spdx_version)
else:
success = False
msg = 'Windows not support spdx format.'
else:
success = False
msg = f'Not supported file extension({file_extension})'
if file_extension == '.xlsx':
success, msg = write_result_to_excel(result_file, scan_item, extended_header, hide_header)
elif file_extension == '.csv':
success, msg, result_file = write_result_to_csv(result_file, scan_item, False, extended_header)
elif file_extension == '.json':
success, msg = write_opossum(result_file, scan_item)
elif file_extension == '.yaml':
success, msg, result_file = write_yaml(result_file, scan_item, False)
else:
success = False
msg = f'Not supported file extension({file_extension})'

return success, msg, result_file
Loading
Loading