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
4 changes: 3 additions & 1 deletion src/fosslight_util/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import platform
import subprocess
import re
from typing import Tuple

logger = logging.getLogger(constant.LOGGER_NAME)
compression_extension = {".tar.bz2", ".tar.gz", ".tar.xz", ".tgz", ".tar", ".zip", ".jar", ".bz2"}
Expand Down Expand Up @@ -111,7 +112,8 @@ def main():
cli_download_and_extract(src_link, target_dir, log_dir)


def cli_download_and_extract(link, target_dir, log_dir, checkout_to="", compressed_only=False):
def cli_download_and_extract(link: str, target_dir: str, log_dir: str, checkout_to: str = "",
compressed_only: bool = False) -> Tuple[bool, str, str, str]:
global logger

success = True
Expand Down
4 changes: 2 additions & 2 deletions src/fosslight_util/output_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def check_output_format(output='', format='', customized_format={}):
return success, msg, output_path, output_file, output_extension


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

Expand All @@ -67,7 +67,7 @@ def write_output_file(output_file_without_ext, file_extension, sheet_list, exten
result_file = output_file_without_ext + file_extension

if file_extension == '.xlsx':
success, msg = write_result_to_excel(result_file, sheet_list, extended_header)
success, msg = write_result_to_excel(result_file, sheet_list, extended_header, hide_header)
elif file_extension == '.csv':
success, msg, result_file = write_result_to_csv(result_file, sheet_list)
elif file_extension == '.json':
Expand Down
19 changes: 16 additions & 3 deletions src/fosslight_util/write_excel.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
logger = logging.getLogger(constant.LOGGER_NAME)


def write_excel_and_csv(filename_without_extension, sheet_list, ignore_os=False, extended_header={}):
def write_excel_and_csv(filename_without_extension, sheet_list, ignore_os=False, extended_header={}, hide_header={}):
success = True
error_msg = ""
success_csv = True
Expand All @@ -47,7 +47,10 @@ 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(f"{filename_without_extension}.xlsx", sheet_list, extended_header)
success, error_msg = write_result_to_excel(f"{filename_without_extension}.xlsx",
sheet_list,
extended_header,
hide_header)

if ignore_os or platform.system() != "Windows":
success_csv, error_msg_csv, output_csv = write_result_to_csv(f"{filename_without_extension}.csv",
Expand Down Expand Up @@ -163,7 +166,7 @@ def write_result_to_csv(output_file, sheet_list_origin, separate_sheet=False, ex
return success, error_msg, output


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

Expand All @@ -182,6 +185,9 @@ def write_result_to_excel(out_file_name, sheet_list, extended_header={}):
pass
worksheet = create_worksheet(workbook, sheet_name, selected_header)
write_result_to_sheet(worksheet, sheet_content_without_header)

if hide_header:
hide_column(worksheet, selected_header, hide_header)
workbook.close()
except Exception as ex:
error_msg = str(ex)
Expand All @@ -198,6 +204,13 @@ def write_result_to_sheet(worksheet, sheet_contents):
row += 1


def hide_column(worksheet, selected_header, hide_header):
for col_idx, sel_hd in enumerate(selected_header):
for hide_hd in hide_header:
if sel_hd == hide_hd:
worksheet.set_column(col_idx, col_idx, None, None, {"hidden": True})


def create_worksheet(workbook, sheet_name, header_row):
if len(sheet_name) > 31:
current_time = str(time.time())
Expand Down
14 changes: 10 additions & 4 deletions tests/test_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,16 @@


def main():
cli_download_and_extract("https://github.com/LGE-OSS/example",
"test_result/download/example", "test_result/download_log/example")
cli_download_and_extract("https://pypi.org/project/filelock/3.4.1",
"test_result/download/filelock", "test_result/download_log/filelock")
success, msg, _, _ = cli_download_and_extract("https://github.com/LGE-OSS/example",
"test_result/download/example",
"test_result/download_log/example")
if not success:
raise Exception(f"Download failed with git:{msg}")
success, msg, _, _ = cli_download_and_extract("https://pypi.org/project/filelock/3.4.1",
"test_result/download/filelock",
"test_result/download_log/filelock")
if not success:
raise Exception(f"Download failed with wget:{msg}")


if __name__ == '__main__':
Expand Down