77import sys
88import logging
99import 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
1412from 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
1815logger = logging .getLogger (LOGGER_NAME )
1916SRC_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
0 commit comments