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: 3 additions & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
tox
pytest
pytest-cov
pytest-flake8
3 changes: 1 addition & 2 deletions src/fosslight_util/constant.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@
# Copyright (c) 2021 LG Electronics Inc.
# SPDX-License-Identifier: Apache-2.0


LOGGER_NAME = "FOSSLight"
LOGGER_NAME = "FOSSLight"
19 changes: 9 additions & 10 deletions src/fosslight_util/help.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,25 @@
import sys

_HELP_MESSAGE_COMMON = """
_______ _______ _______ _______ ___ ___ _______ __ __ _______
_______ _______ _______ _______ ___ ___ _______ __ __ _______
| || || || || | | | | || | | || |
| ___|| _ || _____|| _____|| | | | | ___|| |_| ||_ _|
| |___ | | | || |_____ | |_____ | | | | | | __ | | | |
| ___|| |_| ||_____ ||_____ || |___ | | | || || _ | | |
| | | | _____| | _____| || || | | |_| || | | | | |
|___| |_______||_______||_______||_______||___| |_______||__| |__| |___|
| |___ | | | || |_____ | |_____ | | | | | | __ | | | |
| ___|| |_| ||_____ ||_____ || |___ | | | || || _ | | |
| | | | _____| | _____| || || | | |_| || | | | | |
|___| |_______||_______||_______||_______||___| |_______||__| |__| |___|
"""


class PrintHelpMsg():
message_suffix = ""

def __init__(self, value):
self.message_suffix = value

def print_help_msg(self, exitopt):
print(_HELP_MESSAGE_COMMON)
print(self.message_suffix)

if exitopt == True:
sys.exit()


if exitopt:
sys.exit()
8 changes: 4 additions & 4 deletions src/fosslight_util/set_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
def init_log(log_file, create_file=True, stream_log_level=logging.INFO, file_log_level=logging.DEBUG):

logger = logging.getLogger(constant.LOGGER_NAME)

if not logger.hasHandlers():
logger.setLevel(logging.DEBUG)
log_dir = os.path.dirname(log_file)
Expand All @@ -42,7 +42,7 @@ def init_log(log_file, create_file=True, stream_log_level=logging.INFO, file_log
return logger


def init_log_item(main_package_name="", path_to_analyze= ""):
def init_log_item(main_package_name="", path_to_analyze=""):

_PYTHON_VERSION = sys.version_info[0]
_result_log = {
Expand All @@ -52,8 +52,8 @@ def init_log_item(main_package_name="", path_to_analyze= ""):
}
if main_package_name != "":
pkg_version = pkg_resources.get_distribution(main_package_name).version
_result_log["Tool Info"] = main_package_name +" v."+pkg_version
_result_log["Tool Info"] = main_package_name + " v." + pkg_version
if path_to_analyze != "":
_result_log["Path to analyze"] = path_to_analyze
_result_log["Path to analyze"] = path_to_analyze

return _result_log
3 changes: 2 additions & 1 deletion src/fosslight_util/timer_thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import time
from progress.spinner import Spinner


class TimerThread(threading.Thread):
def __init__(self):
threading.Thread.__init__(self, name=' Thread')
Expand All @@ -14,4 +15,4 @@ def run(self):
spinner = Spinner('')
while True:
time.sleep(1)
spinner.next()
spinner.next()
15 changes: 6 additions & 9 deletions src/fosslight_util/write_excel.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
import time
import logging
import os
import json
import platform
import time
import pandas as pd
from pathlib import Path
import fosslight_util.constant as constant
Expand Down Expand Up @@ -40,11 +38,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(filename_without_extension +
".xlsx", sheet_list)
success, error_msg = write_result_to_excel(filename_without_extension + ".xlsx", sheet_list)

if ignore_os or platform.system() != "Windows":
success_csv, error_msg_csv = write_result_to_csv(filename_without_extension +
".csv", sheet_list)
success_csv, error_msg_csv = write_result_to_csv(filename_without_extension + ".csv", sheet_list)
if not success:
error_msg = "[Error] Writing excel:" + error_msg
if not success_csv:
Expand All @@ -65,7 +62,7 @@ def remove_empty_sheet(sheet_items):
try:
if sheet_items:
for sheet_name, sheet_content in sheet_items.items():
logger.debug("ITEM COUNT:"+str(len(sheet_content)))
logger.debug("ITEM COUNT:" + str(len(sheet_content)))
if len(sheet_content) > 0:
final_sheet_to_print[sheet_name] = sheet_content
cnt_sheet_to_print += 1
Expand All @@ -74,7 +71,7 @@ def remove_empty_sheet(sheet_items):
if cnt_sheet_to_print != 0:
success = True
if len(skip_sheet_name) > 0:
logger.warn("* Empty sheet(not printed):"+ str(skip_sheet_name))
logger.warn("* Empty sheet(not printed):" + str(skip_sheet_name))
except Exception as ex:
logger.warn("* Warning:"+str(ex))

Expand Down Expand Up @@ -157,7 +154,7 @@ def merge_excels(find_excel_dir, final_out):

if len([name for name in files if name.endswith(_find_extension)]) > 0:
writer = pd.ExcelWriter(final_out)
df = pd.DataFrame()

for file in files:
if file.endswith(_find_extension):
f_short_name = os.path.splitext(
Expand Down
2 changes: 1 addition & 1 deletion tests/test_excel.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
def main():
logger = init_log("test_result/excel/log_write_excel.txt")
logger.warning("TESTING - Writing an excel")

sheet_contents = {}
src_sheet_items = [['run_scancode.py', 'fosslight_source',
'3.0.6', 'Apache-2.0', 'https://github.com/LGE-OSS/fosslight_source',
Expand Down
3 changes: 2 additions & 1 deletion tests/test_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ def main():
"""
helpMsg = PrintHelpMsg(_HELP_MESSAGE_TEST)
helpMsg.print_help_msg(True)



if __name__ == '__main__':
main()
4 changes: 3 additions & 1 deletion tests/test_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,18 @@
from _print_log import print_log
from _print_log_with_another_logger import print_log_another_logger


def main():
logger = init_log("test_result/log_file1.txt")
logger.warning("TESTING LOG - from 1st Module")

result_log = init_log_item("fosslight_util")
_str_final_result_log = yaml.safe_dump(result_log, allow_unicode=True)
logger.warning(_str_final_result_log)

print_log()
print_log_another_logger()


if __name__ == '__main__':
main()
1 change: 0 additions & 1 deletion tests/test_timer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2021 LG Electronics Inc.
# SPDX-License-Identifier: Apache-2.0
import os
import time
from fosslight_util.timer_thread import TimerThread

Expand Down
11 changes: 11 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,18 @@ basepython= python3.6
whitelist_externals = cat
ls

[flake8]
max-line-length = 130
exclude = .tox/*

[pytest]
filterwarnings = ignore::DeprecationWarning

[testenv:test_run]
setenv =
PYTHONPATH=.
deps =
-r{toxinidir}/requirements-dev.txt

commands =
# Test - print help msg
Expand All @@ -28,3 +37,5 @@ commands =
cat test_result/excel/OSS-Report.csv
# Test - timer
python tests/test_timer.py
# Test - check PEP8
pytest -v --flake8