2525is_windows = platform .system () == 'Windows'
2626REUSE_CONFIG_FILE = ".reuse/dep5"
2727DEFAULT_EXCLUDE_EXTENSION_FILES = [] # Exclude files from reuse
28+ user_exclude_list = [] # Exclude paths from checking
2829_turn_on_exclude_config = True
2930_check_only_file_mode = False
3031error_items = []
@@ -86,7 +87,7 @@ def exclude_git_related_files(path):
8687 logger .warning (f"Error to get git related files : { ex } " )
8788
8889
89- def find_oss_pkg_info_and_exlcude_file (path ):
90+ def find_oss_pkg_info_and_exclude_file (path ):
9091 global DEFAULT_EXCLUDE_EXTENSION_FILES
9192 oss_pkg_info = []
9293 git_present = shutil .which ("git" )
@@ -96,8 +97,14 @@ def find_oss_pkg_info_and_exlcude_file(path):
9697
9798 try :
9899 for root , dirs , files in os .walk (path ):
100+ if os .path .abspath (root ) in user_exclude_list :
101+ continue
99102 for dir in dirs :
100103 # For hidden folders
104+ dir_path = os .path .join (root , dir )
105+ dir_abs_path = os .path .abspath (dir_path )
106+ if any (os .path .commonpath ([dir_abs_path , exclude_path ]) == exclude_path for exclude_path in user_exclude_list ):
107+ continue
101108 if dir .startswith ("." ):
102109 all_files_in_dir = [os .path .join (root , dir , file )
103110 for file in os .listdir (os .path .join (root , dir ))
@@ -106,17 +113,20 @@ def find_oss_pkg_info_and_exlcude_file(path):
106113 DEFAULT_EXCLUDE_EXTENSION_FILES .extend (all_files_rel_path )
107114
108115 for file in files :
116+ file_path = os .path .join (root , file )
117+ file_abs_path = os .path .abspath (file_path )
118+ if any (os .path .commonpath ([file_abs_path , exclude_path ]) == exclude_path for exclude_path in user_exclude_list ):
119+ continue
109120 file_lower_case = file .lower ()
110- file_abs_path = os .path .join (root , file )
111- file_rel_path = os .path .relpath (file_abs_path , path )
121+ file_rel_path = os .path .relpath (file_path , path )
112122
113123 if any (re .search (re_oss_pkg_pattern , file_lower_case ) for re_oss_pkg_pattern in OSS_PKG_INFO_FILES ) \
114124 or file_lower_case .startswith ("module_license_" ):
115125 oss_pkg_info .append (file_rel_path )
116126 # Exclude hidden files
117127 elif _turn_on_exclude_config and file .startswith ('.' ):
118128 DEFAULT_EXCLUDE_EXTENSION_FILES .append (file_rel_path )
119- elif is_binary (file_abs_path ):
129+ elif is_binary (file_path ):
120130 DEFAULT_EXCLUDE_EXTENSION_FILES .append (file_rel_path )
121131 else :
122132 extension = file_lower_case .split ("." )[- 1 ]
@@ -232,7 +242,7 @@ def precheck_for_project(path_to_find):
232242 missing_license = []
233243 missing_copyright = []
234244
235- oss_pkg_info_files = find_oss_pkg_info_and_exlcude_file (path_to_find )
245+ oss_pkg_info_files = find_oss_pkg_info_and_exclude_file (path_to_find )
236246 if _turn_on_exclude_config :
237247 need_rollback , temp_file_name , temp_dir_name = create_reuse_dep5_file (path_to_find )
238248
@@ -244,13 +254,16 @@ def precheck_for_project(path_to_find):
244254 missing_license = [str (sub ) for sub in set (report .files_without_licenses )]
245255 if not path_to_find .endswith (f"{ os .sep } " ):
246256 path_to_find += f"{ os .sep } "
257+ missing_license = filter_missing_list (missing_license )
247258 missing_license = [sub .replace (path_to_find , '' , 1 ) for sub in missing_license ]
248259
249260 # File list that missing copyright text
250261 missing_copyright = [str (sub ) for sub in set (report .files_without_copyright )]
251262 if not path_to_find .endswith (f"{ os .sep } " ):
252263 path_to_find += f"{ os .sep } "
264+ missing_copyright = filter_missing_list (missing_copyright )
253265 missing_copyright = [sub .replace (path_to_find , '' , 1 ) for sub in missing_copyright ]
266+
254267 except Exception as ex :
255268 dump_error_msg (f"Error prechecker lint: { ex } " , True )
256269
@@ -259,6 +272,15 @@ def precheck_for_project(path_to_find):
259272 return missing_license , missing_copyright , oss_pkg_info_files , project , report
260273
261274
275+ def filter_missing_list (missing_list ):
276+ filtered_list = []
277+ for file in missing_list :
278+ abs_path = os .path .abspath (file )
279+ if not any (os .path .commonpath ([abs_path , path ]) == path for path in user_exclude_list ):
280+ filtered_list .append (file )
281+ return filtered_list
282+
283+
262284def dump_error_msg (error_msg : str , exit = False ):
263285 global error_items
264286 error_items .append (error_msg )
@@ -267,13 +289,14 @@ def dump_error_msg(error_msg: str, exit=False):
267289 sys .exit (1 )
268290
269291
270- def init (path_to_find , output_path , file_list , need_log_file = True ):
292+ def init (path_to_find , output_path , file_list , need_log_file = True , exclude_path = [] ):
271293 global logger , _result_log
294+
272295 if file_list :
273296 _result_log ["File list to check" ] = file_list
274297 path_to_find = file_list
275298 logger , _result_log = init_log (os .path .join (output_path , f"fosslight_log_pre_{ _start_time } .txt" ),
276- need_log_file , logging .INFO , logging .DEBUG , PKG_NAME , path_to_find )
299+ need_log_file , logging .INFO , logging .DEBUG , PKG_NAME , path_to_find , exclude_path )
277300
278301
279302def get_path_to_find (target_path , _check_only_file_mode ):
@@ -305,7 +328,15 @@ def get_path_to_find(target_path, _check_only_file_mode):
305328 return path_to_find , file_to_check_list , _check_only_file_mode
306329
307330
308- def run_lint (target_path , disable , output_file_name , format = '' , need_log_file = True ):
331+ def set_exclude_list (path_to_find , exclude_path ):
332+ global user_exclude_list
333+
334+ for path in exclude_path :
335+ if path .strip != "" :
336+ user_exclude_list .append (os .path .abspath (os .path .join (path_to_find , path )))
337+
338+
339+ def run_lint (target_path , disable , output_file_name , format = '' , need_log_file = True , exclude_path = []):
309340 global _turn_on_exclude_config , _check_only_file_mode , _start_time
310341
311342 file_to_check_list = []
@@ -322,9 +353,10 @@ def run_lint(target_path, disable, output_file_name, format='', need_log_file=Tr
322353 dump_error_msg (f"Error - locale : { ex } " )
323354
324355 path_to_find , file_to_check_list , _check_only_file_mode = get_path_to_find (target_path , _check_only_file_mode )
356+ set_exclude_list (path_to_find , exclude_path )
325357
326358 result_file , output_path , output_extension = create_result_file (output_file_name , format , _start_time )
327- init (path_to_find , output_path , file_to_check_list , need_log_file )
359+ init (path_to_find , output_path , file_to_check_list , need_log_file , exclude_path )
328360
329361 if os .path .isdir (path_to_find ):
330362 oss_pkg_info = []
@@ -353,7 +385,8 @@ def run_lint(target_path, disable, output_file_name, format='', need_log_file=Tr
353385 _check_only_file_mode ,
354386 file_to_check_list ,
355387 error_items ,
356- DEFAULT_EXCLUDE_EXTENSION_FILES )
388+ DEFAULT_EXCLUDE_EXTENSION_FILES ,
389+ user_exclude_list )
357390
358391 success , exit_code = write_result_file (result_file , output_extension , _exit_code ,
359392 result_item , _result_log , project , path_to_find )
0 commit comments