Skip to content

Commit

Permalink
Include the parent directory for ScanCode
Browse files Browse the repository at this point in the history
  • Loading branch information
soimkim committed Aug 31, 2023
1 parent 14060bb commit ad4d843
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ progress
pyyaml
beautifulsoup4
fosslight_util>=1.4.29
fosslight_source>=1.7.0
fosslight_source==1.7.0
fosslight_dependency>=3.7.4
fosslight_binary>=4.1.24
fosslight_prechecker>=3.0.1
19 changes: 18 additions & 1 deletion src/fosslight_scanner/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from fosslight_util.write_scancodejson import write_scancodejson
from fosslight_util.read_excel import read_oss_report
from fosslight_util.output_format import write_output_file
from pathlib import Path

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


def create_scancodejson(final_report, output_extension, ui_mode_report):
def create_scancodejson(final_report, output_extension, ui_mode_report, src_path=""):
success = True
err_msg = ''

oss_total_list = []
root_dir = ""

try:
parent = os.path.basename(os.path.abspath(src_path))
two_depth_parent = os.path.basename(Path(os.path.abspath(src_path)).parents[0])
root_dir = os.path.join(two_depth_parent, parent)
except Exception:
root_dir = ""

try:
oss_total_list = get_osslist(os.path.dirname(final_report), os.path.basename(final_report),
output_extension, '')

if root_dir:
for oss in oss_total_list:
tmp_path_list = oss.source_name_or_path
oss.source_name_or_path = ""
oss.source_name_or_path = [os.path.join(root_dir, path) for path in tmp_path_list]

write_scancodejson(os.path.dirname(ui_mode_report), os.path.basename(ui_mode_report),
oss_total_list)
except Exception as ex:
Expand Down
2 changes: 1 addition & 1 deletion src/fosslight_scanner/fosslight_scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ def run_scanner(src_path, dep_arguments, output_path, keep_raw_data=False,

if ui_mode:
ui_mode_report = f"{output_file_without_ext}.json"
success, err_msg = create_scancodejson(final_report, output_extension, ui_mode_report)
success, err_msg = create_scancodejson(final_report, output_extension, ui_mode_report, src_path)
if success and os.path.isfile(ui_mode_report):
logger.info(f'Generated the ui mode result file: {ui_mode_report}')
else:
Expand Down

0 comments on commit ad4d843

Please sign in to comment.