37
37
_exclude_dir = ['node_moduels' , 'venv' ]
38
38
39
39
40
- def find_package_manager (input_dir ):
40
+ def find_package_manager (input_dir , abs_path_to_exclude = [] ):
41
41
ret = True
42
42
manifest_file_name = []
43
43
for value in const .SUPPORT_PACKAE .values ():
@@ -52,7 +52,14 @@ def find_package_manager(input_dir):
52
52
continue
53
53
if os .path .basename (parent ) in _exclude_dir :
54
54
continue
55
+ if os .path .abspath (parent ) in abs_path_to_exclude :
56
+ continue
55
57
for file in files :
58
+ file_path = os .path .join (parent , file )
59
+ file_abs_path = os .path .abspath (file_path )
60
+ if any (os .path .commonpath ([file_abs_path , exclude_path ]) == exclude_path
61
+ for exclude_path in abs_path_to_exclude ):
62
+ continue
56
63
if file in manifest_file_name :
57
64
found_manifest_file .append (file )
58
65
if len (found_manifest_file ) > 0 :
@@ -83,8 +90,9 @@ def find_package_manager(input_dir):
83
90
return ret , found_package_manager , input_dir
84
91
85
92
86
- def run_dependency_scanner (package_manager = '' , input_dir = '' , output_dir_file = '' , pip_activate_cmd = '' , pip_deactivate_cmd = '' ,
87
- output_custom_dir = '' , app_name = const .default_app_name , github_token = '' , format = '' , direct = True ):
93
+ def run_dependency_scanner (package_manager = '' , input_dir = '' , output_dir_file = '' , pip_activate_cmd = '' ,
94
+ pip_deactivate_cmd = '' , output_custom_dir = '' , app_name = const .default_app_name ,
95
+ github_token = '' , format = '' , direct = True , path_to_exclude = []):
88
96
global logger
89
97
90
98
ret = True
@@ -117,7 +125,8 @@ def run_dependency_scanner(package_manager='', input_dir='', output_dir_file='',
117
125
sys .exit (1 )
118
126
119
127
logger , _result_log = init_log (os .path .join (output_path , "fosslight_log_dep_" + _start_time + ".txt" ),
120
- True , logging .INFO , logging .DEBUG , _PKG_NAME )
128
+ True , logging .INFO , logging .DEBUG , _PKG_NAME , "" , path_to_exclude )
129
+ abs_path_to_exclude = [os .path .abspath (os .path .join (input_dir , path )) for path in path_to_exclude ]
121
130
122
131
logger .info (f"Tool Info : { _result_log ['Tool Info' ]} " )
123
132
@@ -151,7 +160,7 @@ def run_dependency_scanner(package_manager='', input_dir='', output_dir_file='',
151
160
found_package_manager = {}
152
161
if autodetect :
153
162
try :
154
- ret , found_package_manager , input_dir = find_package_manager (input_dir )
163
+ ret , found_package_manager , input_dir = find_package_manager (input_dir , abs_path_to_exclude )
155
164
os .chdir (input_dir )
156
165
except Exception as e :
157
166
logger .error (f'Fail to find package manager: { e } ' )
@@ -188,7 +197,8 @@ def run_dependency_scanner(package_manager='', input_dir='', output_dir_file='',
188
197
fail_pm .append (f"{ pm } ({ ', ' .join (manifest_file_name )} )" )
189
198
cover = CoverItem (tool_name = _PKG_NAME ,
190
199
start_time = _start_time ,
191
- input_path = input_dir )
200
+ input_path = input_dir ,
201
+ exclude_path = path_to_exclude )
192
202
cover_comment_arr = []
193
203
if len (found_package_manager .keys ()) > 0 :
194
204
if len (success_pm ) > 0 :
@@ -231,6 +241,7 @@ def main():
231
241
package_manager = ''
232
242
input_dir = ''
233
243
output_dir = ''
244
+ path_to_exclude = []
234
245
pip_activate_cmd = ''
235
246
pip_deactivate_cmd = ''
236
247
output_custom_dir = ''
@@ -244,6 +255,7 @@ def main():
244
255
parser .add_argument ('-v' , '--version' , action = 'store_true' , required = False )
245
256
parser .add_argument ('-m' , '--manager' , nargs = 1 , type = str , default = '' , required = False )
246
257
parser .add_argument ('-p' , '--path' , nargs = 1 , type = str , required = False )
258
+ parser .add_argument ('-e' , '--exclude' , nargs = '*' , required = False , default = [])
247
259
parser .add_argument ('-o' , '--output' , nargs = 1 , type = str , required = False )
248
260
parser .add_argument ('-a' , '--activate' , nargs = 1 , type = str , default = '' , required = False )
249
261
parser .add_argument ('-d' , '--deactivate' , nargs = 1 , type = str , default = '' , required = False )
@@ -268,6 +280,8 @@ def main():
268
280
package_manager = '' .join (args .manager )
269
281
if args .path : # -p option
270
282
input_dir = '' .join (args .path )
283
+ if args .exclude : # -e option
284
+ path_to_exclude = args .exclude
271
285
if args .output : # -o option
272
286
output_dir = '' .join (args .output )
273
287
if args .activate : # -a option
@@ -301,7 +315,7 @@ def main():
301
315
sys .exit (0 )
302
316
303
317
run_dependency_scanner (package_manager , input_dir , output_dir , pip_activate_cmd , pip_deactivate_cmd ,
304
- output_custom_dir , app_name , github_token , format , direct )
318
+ output_custom_dir , app_name , github_token , format , direct , path_to_exclude )
305
319
306
320
307
321
if __name__ == '__main__' :
0 commit comments