@@ -44,6 +44,7 @@ def main():
4444 _result_log = {}
4545
4646 path_to_scan = os .getcwd ()
47+ path_to_exclude = []
4748 write_json_file = False
4849 output_file_name = ""
4950 print_matched_text = False
@@ -65,6 +66,7 @@ def main():
6566 parser .add_argument ('-s' , '--scanner' , nargs = 1 , type = str , required = False , default = 'all' )
6667 parser .add_argument ('-t' , '--timeout' , type = int , required = False , default = 120 )
6768 parser .add_argument ('-c' , '--cores' , type = int , required = False , default = - 1 )
69+ parser .add_argument ('-e' , '--exclude' , nargs = '*' , required = False , default = [])
6870 parser .add_argument ('--no_correction' , action = 'store_true' , required = False )
6971 parser .add_argument ('--correct_fpath' , nargs = 1 , type = str , required = False )
7072
@@ -78,6 +80,8 @@ def main():
7880 path_to_scan = os .getcwd ()
7981 else :
8082 path_to_scan = '' .join (args .path )
83+ if args .exclude :
84+ path_to_exclude = args .exclude
8185 if args .json :
8286 write_json_file = True
8387 output_file_name = '' .join (args .output )
@@ -103,7 +107,8 @@ def main():
103107 if os .path .isdir (path_to_scan ):
104108 result = []
105109 result = run_scanners (path_to_scan , output_file_name , write_json_file , core , True ,
106- print_matched_text , format , time_out , correct_mode , correct_filepath , selected_scanner )
110+ print_matched_text , format , time_out , correct_mode , correct_filepath ,
111+ selected_scanner , path_to_exclude )
107112 _result_log ["Scan Result" ] = result [1 ]
108113
109114 try :
@@ -115,9 +120,26 @@ def main():
115120 sys .exit (1 )
116121
117122
123+ def count_files (path_to_scan , path_to_exclude ):
124+ total_files = 0
125+ excluded_files = 0
126+ abs_path_to_exclude = [os .path .abspath (os .path .join (path_to_scan , path )) for path in path_to_exclude ]
127+
128+ for root , _ , files in os .walk (path_to_scan ):
129+ for file in files :
130+ file_path = os .path .join (root , file )
131+ abs_file_path = os .path .abspath (file_path )
132+ if any (os .path .commonpath ([abs_file_path , exclude_path ]) == exclude_path
133+ for exclude_path in abs_path_to_exclude ):
134+ excluded_files += 1
135+ total_files += 1
136+
137+ return total_files , excluded_files
138+
139+
118140def create_report_file (_start_time , merged_result , license_list , scanoss_result , selected_scanner , need_license = False ,
119141 output_path = "" , output_file = "" , output_extension = "" , correct_mode = True , correct_filepath = "" ,
120- path_to_scan = "" ):
142+ path_to_scan = "" , path_to_exclude = [] ):
121143 """
122144 Create report files for given scanned result.
123145
@@ -146,9 +168,10 @@ def create_report_file(_start_time, merged_result, license_list, scanoss_result,
146168
147169 cover = CoverItem (tool_name = _PKG_NAME ,
148170 start_time = _start_time ,
149- input_path = path_to_scan )
150- files_count = sum ([len (files ) for r , d , files in os .walk (path_to_scan )])
151- cover .comment = f"Total number of files: { files_count } "
171+ input_path = path_to_scan ,
172+ exclude_path = path_to_exclude )
173+ files_count , removed_files_count = count_files (path_to_scan , path_to_exclude )
174+ cover .comment = f"Total number of files / removed files: { files_count } / { removed_files_count } "
152175 if len (merged_result ) == 0 :
153176 if files_count < 1 :
154177 cover .comment += "(No file detected.)"
@@ -224,7 +247,7 @@ def merge_results(scancode_result=[], scanoss_result=[], spdx_downloads={}):
224247
225248def run_scanners (path_to_scan , output_file_name = "" , write_json_file = False , num_cores = - 1 , called_by_cli = True ,
226249 print_matched_text = False , format = "" , time_out = 120 , correct_mode = True , correct_filepath = "" ,
227- selected_scanner = 'all' ):
250+ selected_scanner = 'all' , path_to_exclude = [] ):
228251 """
229252 Run Scancode and scanoss.py for the given path.
230253
@@ -252,7 +275,7 @@ def run_scanners(path_to_scan, output_file_name="", write_json_file=False, num_c
252275
253276 success , msg , output_path , output_file , output_extension = check_output_format (output_file_name , format )
254277 logger , result_log = init_log (os .path .join (output_path , f"fosslight_log_src_{ start_time } .txt" ),
255- True , logging .INFO , logging .DEBUG , _PKG_NAME , path_to_scan )
278+ True , logging .INFO , logging .DEBUG , _PKG_NAME , path_to_scan , path_to_exclude )
256279 if output_extension != '.xlsx' and output_extension and print_matched_text :
257280 logger .warning ("-m option is only available for excel." )
258281 print_matched_text = False
@@ -261,14 +284,17 @@ def run_scanners(path_to_scan, output_file_name="", write_json_file=False, num_c
261284 success , result_log [RESULT_KEY ], scancode_result , license_list = run_scan (path_to_scan , output_file_name ,
262285 write_json_file , num_cores , True ,
263286 print_matched_text , format , called_by_cli ,
264- time_out , correct_mode , correct_filepath )
287+ time_out , correct_mode , correct_filepath ,
288+ path_to_exclude )
265289 if selected_scanner == 'scanoss' or selected_scanner == 'all' or selected_scanner == '' :
266- scanoss_result = run_scanoss_py (path_to_scan , output_file_name , format , True , write_json_file , num_cores )
290+ scanoss_result = run_scanoss_py (path_to_scan , output_file_name , format , True ,
291+ write_json_file , num_cores , path_to_exclude )
267292 if selected_scanner in SCANNER_TYPE :
268- spdx_downloads = get_spdx_downloads (path_to_scan )
293+ spdx_downloads = get_spdx_downloads (path_to_scan , path_to_exclude )
269294 merged_result = merge_results (scancode_result , scanoss_result , spdx_downloads )
270- create_report_file (start_time , merged_result , license_list , scanoss_result , selected_scanner , print_matched_text ,
271- output_path , output_file , output_extension , correct_mode , correct_filepath , path_to_scan )
295+ create_report_file (start_time , merged_result , license_list , scanoss_result , selected_scanner ,
296+ print_matched_text , output_path , output_file , output_extension , correct_mode ,
297+ correct_filepath , path_to_scan , path_to_exclude )
272298 else :
273299 print_help_msg_source_scanner ()
274300 result_log [RESULT_KEY ] = "Unsupported scanner"
0 commit comments