Skip to content

Commit 2acef36

Browse files
committed
update ui mode feature
Signed-off-by: jiyeong.seok <[email protected]>
1 parent 4ec250a commit 2acef36

File tree

3 files changed

+44
-55
lines changed

3 files changed

+44
-55
lines changed

requirements.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ openpyxl
44
progress
55
pyyaml
66
beautifulsoup4
7-
fosslight_util~=1.4.48
8-
fosslight_source~=1.7.8
9-
fosslight_dependency~=3.15.1
10-
fosslight_binary~=4.1.30
7+
fosslight_util>=2.0.0
8+
fosslight_source>=2.0.0
9+
fosslight_dependency>=4.0.0
10+
fosslight_binary>=5.0.0
1111
fosslight_prechecker==3.0.27

src/fosslight_scanner/common.py

Lines changed: 32 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,10 @@
77
import sys
88
import logging
99
import shutil
10-
import pandas as pd
11-
import yaml
12-
from fosslight_util.constant import LOGGER_NAME, FOSSLIGHT_SOURCE, FOSSLIGHT_BINARY
13-
from fosslight_util.parsing_yaml import parsing_yml
10+
import copy
11+
from fosslight_util.constant import LOGGER_NAME, FOSSLIGHT_SOURCE, FOSSLIGHT_BINARY, FOSSLIGHT_DEPENDENCY
1412
from fosslight_util.write_scancodejson import write_scancodejson
15-
from fosslight_util.read_excel import read_oss_report
16-
from fosslight_util.oss_item import OssItem
13+
from fosslight_util.oss_item import OssItem, FileItem
1714

1815
logger = logging.getLogger(LOGGER_NAME)
1916
SRC_SHEET = 'SRC_FL_Source'
@@ -104,11 +101,9 @@ def update_oss_item(scan_item, oss_name, oss_version, download_loc):
104101
return scan_item
105102

106103

107-
def create_scancodejson(final_report, output_extension, ui_mode_report, src_path=""):
104+
def create_scancodejson(all_scan_item_origin, ui_mode_report, src_path=""):
108105
success = True
109106
err_msg = ''
110-
111-
oss_total_list = []
112107
root_dir = ""
113108
root_strip = ""
114109
try:
@@ -120,28 +115,37 @@ def create_scancodejson(final_report, output_extension, ui_mode_report, src_path
120115
root_dir = ""
121116

122117
try:
123-
item_without_oss = OssItem("")
124-
oss_total_list = get_osslist(os.path.dirname(final_report), os.path.basename(final_report),
125-
output_extension, '')
118+
all_scan_item = copy.deepcopy(all_scan_item_origin)
119+
if FOSSLIGHT_DEPENDENCY in all_scan_item.file_items:
120+
del all_scan_item.file_items[FOSSLIGHT_DEPENDENCY]
126121
if src_path:
127-
for root, dirs, files in os.walk(src_path):
122+
fileitems_without_oss = []
123+
for root, _, files in os.walk(src_path):
128124
root = root.replace(root_strip, "")
129125
for file in files:
126+
fi_without_oss = FileItem('')
127+
included = False
130128
item_path = os.path.join(root, file)
131129
item_path = item_path.replace(parent + os.path.sep, '', 1)
132-
included = any(item_path in x.source_name_or_path for x in oss_total_list)
130+
131+
for file_items in all_scan_item.file_items.values():
132+
for file_item in file_items:
133+
if file_item.source_name_or_path:
134+
if file_item.source_name_or_path == item_path:
135+
included = True
136+
break
133137
if not included:
134-
item_without_oss.source_name_or_path = item_path
135-
if len(item_without_oss.source_name_or_path) > 0:
136-
oss_total_list.append(item_without_oss)
138+
fi_without_oss.source_name_or_path = item_path
139+
fileitems_without_oss.append(fi_without_oss)
140+
if len(fileitems_without_oss) > 0:
141+
all_scan_item.file_items[FOSSLIGHT_SOURCE].extend(fileitems_without_oss)
137142
if root_dir:
138-
for oss in oss_total_list:
139-
tmp_path_list = oss.source_name_or_path
140-
oss.source_name_or_path = ""
141-
oss.source_name_or_path = [os.path.join(root_dir, path) for path in tmp_path_list]
142-
143+
for file_items in all_scan_item.file_items.values():
144+
for fi in file_items:
145+
if fi.source_name_or_path:
146+
fi.source_name_or_path = os.path.join(root_dir, fi.source_name_or_path)
143147
write_scancodejson(os.path.dirname(ui_mode_report), os.path.basename(ui_mode_report),
144-
oss_total_list)
148+
all_scan_item)
145149
except Exception as ex:
146150
err_msg = ex
147151
success = False
@@ -160,10 +164,10 @@ def correct_scanner_result(all_scan_item):
160164
try:
161165
remove_src_idx_list = []
162166
for idx_src, src_fileitem in enumerate(src_fileitems):
163-
src_fileitem.exclude = check_exclude_dir(src_fileitem.source_name_or_path)
167+
src_fileitem.exclude = check_exclude_dir(src_fileitem.source_name_or_path, src_fileitem.exclude)
164168
dup_flag = False
165169
for bin_fileitem in bin_fileitems:
166-
bin_fileitem.exclude = check_exclude_dir(bin_fileitem.source_name_or_path)
170+
bin_fileitem.exclude = check_exclude_dir(bin_fileitem.source_name_or_path, bin_fileitem.exclude)
167171
if src_fileitem.source_name_or_path == bin_fileitem.source_name_or_path:
168172
dup_flag = True
169173
src_all_licenses_non_empty = all(oss_item.license for oss_item in src_fileitem.oss_items)
@@ -193,24 +197,9 @@ def correct_scanner_result(all_scan_item):
193197
return all_scan_item
194198

195199

196-
def get_osslist(_output_dir, output_file, output_extension, sheet_name=''):
197-
err_reason = ''
198-
oss_list = []
199-
oss_file_with_fullpath = os.path.join(_output_dir, output_file)
200-
201-
if os.path.exists(oss_file_with_fullpath):
202-
if output_extension == '.xlsx':
203-
oss_list = read_oss_report(oss_file_with_fullpath, sheet_name)
204-
elif output_extension == '.yaml':
205-
oss_list, _, err_reason = parsing_yml(oss_file_with_fullpath, _output_dir)
206-
else:
207-
err_reason = f'Not supported extension: {output_extension}'
208-
if err_reason:
209-
logger.info(f'get_osslist: {err_reason}')
210-
return oss_list
211-
212-
213-
def check_exclude_dir(source_name_or_path):
200+
def check_exclude_dir(source_name_or_path, file_item_exclude):
201+
if file_item_exclude:
202+
return True
214203
_exclude_dirs = ["venv", "node_modules", "Pods", "Carthage"]
215204
exclude = False
216205

src/fosslight_scanner/fosslight_scanner.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
from fosslight_util.output_format import write_output_file
3131

3232
from .common import (
33-
copy_file, call_analysis_api, update_oss_item,
33+
call_analysis_api, update_oss_item,
3434
correct_scanner_result, create_scancodejson
3535
)
3636
from ._run_compare import run_compare
@@ -198,12 +198,12 @@ def run_scanner(src_path, dep_arguments, output_path, keep_raw_data=False,
198198

199199
if run_bin:
200200
success, result = call_analysis_api(src_path, "Binary Analysis",
201-
1, binary_analysis.find_binaries,
202-
abs_path,
203-
os.path.join(_output_dir, output_files["BIN"]),
204-
"", db_url, binary_simple,
205-
correct_mode, correct_fpath,
206-
path_to_exclude=path_to_exclude)
201+
1, binary_analysis.find_binaries,
202+
abs_path,
203+
os.path.join(_output_dir, output_files["BIN"]),
204+
"", db_url, binary_simple,
205+
correct_mode, correct_fpath,
206+
path_to_exclude=path_to_exclude)
207207
if success:
208208
all_scan_item.file_items.update(result.file_items)
209209
all_cover_items.append(result.cover)
@@ -251,7 +251,7 @@ def run_scanner(src_path, dep_arguments, output_path, keep_raw_data=False,
251251

252252
if ui_mode:
253253
ui_mode_report = f"{output_file_without_ext}.json"
254-
success, err_msg = create_scancodejson(final_report, output_extension, ui_mode_report, src_path)
254+
success, err_msg = create_scancodejson(all_scan_item, ui_mode_report, src_path)
255255
if success and os.path.isfile(ui_mode_report):
256256
logger.info(f'Generated the ui mode result file: {ui_mode_report}')
257257
else:

0 commit comments

Comments
 (0)