Skip to content
Merged
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
17 changes: 11 additions & 6 deletions src/fosslight_util/output_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,25 @@
SUPPORT_FORMAT = {'excel': '.xlsx', 'csv': '.csv', 'opossum': '.json'}


def check_output_format(output='', format=''):
def check_output_format(output='', format='', customized_format={}):
success = True
msg = ''
output_path = ''
output_file = ''
output_extension = ''

if customized_format:
support_format = customized_format
else:
support_format = SUPPORT_FORMAT

if format:
format = format.lower()
if format not in list(SUPPORT_FORMAT.keys()):
if format not in list(support_format.keys()):
success = False
msg = 'Add the supported format with -f option: ' + ', '.join(list(SUPPORT_FORMAT.keys()))
msg = 'Add the supported format with -f option: ' + ', '.join(list(support_format.keys()))
else:
output_extension = SUPPORT_FORMAT[format]
output_extension = support_format[format]

if success:
if output != '':
Expand All @@ -34,7 +39,7 @@ def check_output_format(output='', format=''):
basename_file, basename_extension = os.path.splitext(basename)
if basename_extension:
find_ext = False
for _format, _ext in SUPPORT_FORMAT.items():
for _format, _ext in support_format.items():
if basename_extension == _ext:
find_ext = True
if format:
Expand All @@ -46,7 +51,7 @@ def check_output_format(output='', format=''):
output_extension = _ext
if not find_ext:
success = False
msg = 'Enter the supported file extension: ' + ', '.join(list(SUPPORT_FORMAT.values()))
msg = 'Enter the supported file extension: ' + ', '.join(list(support_format.values()))
else:
output_path = output

Expand Down