Skip to content

Commit ad4d843

Browse files
committed
Include the parent directory for ScanCode
1 parent 14060bb commit ad4d843

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ progress
66
pyyaml
77
beautifulsoup4
88
fosslight_util>=1.4.29
9-
fosslight_source>=1.7.0
9+
fosslight_source==1.7.0
1010
fosslight_dependency>=3.7.4
1111
fosslight_binary>=4.1.24
1212
fosslight_prechecker>=3.0.1

src/fosslight_scanner/common.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from fosslight_util.write_scancodejson import write_scancodejson
1818
from fosslight_util.read_excel import read_oss_report
1919
from fosslight_util.output_format import write_output_file
20+
from pathlib import Path
2021

2122
logger = logging.getLogger(constant.LOGGER_NAME)
2223
SRC_SHEET = 'SRC_FL_Source'
@@ -202,14 +203,30 @@ def merge_yamls(_output_dir, merge_yaml_files, final_report, remove_src_data=Fal
202203
return success, err_msg
203204

204205

205-
def create_scancodejson(final_report, output_extension, ui_mode_report):
206+
def create_scancodejson(final_report, output_extension, ui_mode_report, src_path=""):
206207
success = True
207208
err_msg = ''
208209

209210
oss_total_list = []
211+
root_dir = ""
212+
213+
try:
214+
parent = os.path.basename(os.path.abspath(src_path))
215+
two_depth_parent = os.path.basename(Path(os.path.abspath(src_path)).parents[0])
216+
root_dir = os.path.join(two_depth_parent, parent)
217+
except Exception:
218+
root_dir = ""
219+
210220
try:
211221
oss_total_list = get_osslist(os.path.dirname(final_report), os.path.basename(final_report),
212222
output_extension, '')
223+
224+
if root_dir:
225+
for oss in oss_total_list:
226+
tmp_path_list = oss.source_name_or_path
227+
oss.source_name_or_path = ""
228+
oss.source_name_or_path = [os.path.join(root_dir, path) for path in tmp_path_list]
229+
213230
write_scancodejson(os.path.dirname(ui_mode_report), os.path.basename(ui_mode_report),
214231
oss_total_list)
215232
except Exception as ex:

src/fosslight_scanner/fosslight_scanner.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ def run_scanner(src_path, dep_arguments, output_path, keep_raw_data=False,
237237

238238
if ui_mode:
239239
ui_mode_report = f"{output_file_without_ext}.json"
240-
success, err_msg = create_scancodejson(final_report, output_extension, ui_mode_report)
240+
success, err_msg = create_scancodejson(final_report, output_extension, ui_mode_report, src_path)
241241
if success and os.path.isfile(ui_mode_report):
242242
logger.info(f'Generated the ui mode result file: {ui_mode_report}')
243243
else:

0 commit comments

Comments
 (0)