Skip to content

Commit 3136413

Browse files
committed
Print environment info to log
1 parent 2f02589 commit 3136413

File tree

5 files changed

+56
-20
lines changed

5 files changed

+56
-20
lines changed

requirements.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
scancode-toolkit<=21.2.25
1+
scancode-toolkit<=21.3.31
22
typecode_libmagic
33
XlsxWriter
4-
fosslight_util
4+
fosslight_util
5+
PyYAML

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
if __name__ == "__main__":
1515
setup(
1616
name='fosslight_source',
17-
version='1.4.1',
17+
version='1.4.2',
1818
package_dir={"": "src"},
1919
packages=find_packages(where='src'),
2020
description='FOSSLight Source',

src/fosslight_source/_parsing_scancode_file_item.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def parsing_file_item(scancode_file_list):
100100

101101
rc = True
102102
scancode_file_item = []
103-
logger.warn("|---TOTAL FILE COUNT:"+str(len(scancode_file_list)))
103+
msg ="TOTAL FILE COUNT: "+str(len(scancode_file_list))+"\n"
104104

105105
prev_dir = ""
106106
prev_dir_value = False
@@ -177,7 +177,7 @@ def parsing_file_item(scancode_file_list):
177177

178178
scancode_file_item.append(result_item)
179179
except Exception as ex:
180-
logger.warn("Error Parsing item-"+str(ex))
180+
msg += "* Error Parsing item:"+str(ex)
181181
rc = False
182182

183-
return rc, scancode_file_item
183+
return rc, scancode_file_item, msg.strip()

src/fosslight_source/convert_scancode.py

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,22 @@
1212
import logging
1313
import fosslight_util.constant as constant
1414
from fosslight_util.set_log import init_log
15-
15+
from fosslight_util.set_log import init_log_item
16+
import yaml
1617
from ._write_oss_report_src import write_result_to_csv, write_result_to_excel
1718
from ._parsing_scancode_file_item import parsing_file_item
1819

1920
logger = logging.getLogger(constant.LOGGER_NAME)
21+
_PKG_NAME = "fosslight_source"
22+
_ERROR_PREFIX = "* Error : "
2023

2124

2225
def convert_json_to_excel(scancode_json, excel_name, csv_name):
2326
file_list = []
27+
_result_log = init_log_item(_PKG_NAME)
28+
msg = ""
29+
success = True
30+
2431
try:
2532
sheet_list = {}
2633
if os.path.isfile(scancode_json):
@@ -44,13 +51,25 @@ def convert_json_to_excel(scancode_json, excel_name, csv_name):
4451

4552
if len(sheet_list) > 0:
4653
write_result_to_excel(excel_name, sheet_list)
54+
_result_log["OSS Report"] = excel_name
55+
4756
if platform.system() != "Windows":
4857
write_result_to_csv(csv_name, sheet_list)
4958
else:
50-
logger.warn("There is no item to print in OSS-Report.")
59+
msg = "There is no item to print in OSS-Report."
5160

5261
except Exception as ex:
53-
logger.warn(str(ex))
62+
success = False
63+
msg = _ERROR_PREFIX+str(ex)
64+
65+
scan_result_msg = str(success)+" "+msg
66+
_result_log["Scan Result"] = scan_result_msg.strip()
67+
68+
try:
69+
_str_final_result_log = yaml.safe_dump(_result_log, allow_unicode=True, sort_keys=True)
70+
logger.warn("\n"+_str_final_result_log)
71+
except Exception as ex:
72+
logger.warn(_ERROR_PREFIX+"Failed to print result log. "+ str(ex))
5473

5574
return file_list
5675

@@ -61,9 +80,10 @@ def get_detected_licenses_from_scancode(scancode_json_file):
6180
logger.warn("Start parsing " + scancode_json_file)
6281
with open(scancode_json_file, "r") as st_json:
6382
st_python = json.load(st_json)
64-
rc, file_list = parsing_file_item(st_python["files"])
83+
rc, file_list, msg= parsing_file_item(st_python["files"])
84+
logger.warn("|---"+msg)
6585
except Exception as error:
66-
logger.warn("Error Parsing - "+str(error))
86+
logger.warn(_ERROR_PREFIX+"Parsing -"+str(error))
6787
logger.warn("|---Number of files detected: " + str(len(file_list)))
6888
return file_list
6989

src/fosslight_source/run_scancode.py

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,20 @@
1010
import platform
1111
import getopt
1212
import logging
13+
import yaml
1314
from scancode import cli
1415
from datetime import datetime
1516
import fosslight_util.constant as constant
1617
from fosslight_util.set_log import init_log
18+
from fosslight_util.set_log import init_log_item
19+
from fosslight_util.timer_thread import TimerThread
1720
from ._write_oss_report_src import write_result_to_csv, write_result_to_excel
1821
from ._parsing_scancode_file_item import parsing_file_item
19-
from fosslight_util.timer_thread import TimerThread
2022

2123
logger = logging.getLogger(constant.LOGGER_NAME)
2224
warnings.filterwarnings("ignore", category=FutureWarning)
23-
25+
_PKG_NAME = "fosslight_source"
26+
_ERROR_PREFIX = "* Error : "
2427

2528
def print_help_msg():
2629
print("* Required : -p path_to_scan")
@@ -52,7 +55,7 @@ def main():
5255
timer = TimerThread()
5356
timer.setDaemon(True)
5457
timer.start()
55-
success, msg = run_scan(_path_to_scan, _output_file, _write_json_file, -1)
58+
success, result_log = run_scan(_path_to_scan, _output_file, _write_json_file, -1)
5659

5760

5861
def run_scan(path_to_scan, output_file_name="",
@@ -61,6 +64,8 @@ def run_scan(path_to_scan, output_file_name="",
6164

6265
success = True
6366
msg = ""
67+
_str_final_result_log = ""
68+
_result_log = {}
6469

6570
_windows = platform.system() == "Windows"
6671
start_time = datetime.now().strftime('%Y-%m-%d_%H-%M-%S')
@@ -77,6 +82,7 @@ def run_scan(path_to_scan, output_file_name="",
7782
output_dir = os.path.dirname(os.path.abspath(output_file_name))
7883

7984
logger = init_log(os.path.join(output_dir, "fosslight_src_log_"+start_time+".txt"))
85+
_result_log = init_log_item(_PKG_NAME, path_to_scan)
8086

8187
if path_to_scan == "":
8288
if _windows:
@@ -102,29 +108,38 @@ def run_scan(path_to_scan, output_file_name="",
102108
if rc:
103109
for key, value in results.items():
104110
if key == "files":
105-
rc, result_list = parsing_file_item(value)
111+
rc, result_list, parsing_msg = parsing_file_item(value)
112+
_result_log["Parsing Log"] = parsing_msg
106113
if rc:
107114
if len(result_list) > 0:
108115
sheet_list["SRC"] = result_list
109116
write_result_to_excel(
110117
output_file + ".xlsx", sheet_list)
118+
_result_log["OSS Report"] = output_file
111119
else:
112120
msg = "* There is no item"\
113121
" to print in OSS-Report."
114122
if not _windows:
115123
write_result_to_csv(output_csv_file + ".csv", sheet_list)
116124
else:
117-
msg = "* Source code analysis failed."
125+
msg = _ERROR_PREFIX+"Source code analysis failed."
118126
success = False
119127
except Exception as ex:
120128
success = False
121-
msg = '* Error :' + str(ex)
129+
msg = _ERROR_PREFIX + str(ex)
122130
else:
123131
success = False
124-
msg = "* Check the path to scan. :" + path_to_scan
132+
msg = _ERROR_PREFIX+"Check the path to scan. :" + path_to_scan
125133

126-
logger.warn("* Scan Result:" + str(success)+"\n"+msg)
127-
return success, msg
134+
scan_result_msg = str(success)+" "+msg
135+
_result_log["Scan Result"] = scan_result_msg.strip()
136+
_result_log["Output Directory"] = output_dir
137+
try:
138+
_str_final_result_log = yaml.safe_dump(_result_log, allow_unicode=True, sort_keys=True)
139+
logger.warn("\n"+_str_final_result_log)
140+
except Exception as ex:
141+
logger.warn(_ERROR_PREFIX+"Failed to print result log. "+ str(ex))
142+
return success, _str_final_result_log
128143

129144

130145
if __name__ == '__main__':

0 commit comments

Comments
 (0)