16
16
from datetime import datetime
17
17
from fosslight_binary import binary_analysis
18
18
from fosslight_dependency .run_dependency_scanner import run_dependency_scanner
19
- from fosslight_util .download import cli_download_and_extract
19
+ from fosslight_util .download import cli_download_and_extract , compression_extension
20
+ from fosslight_util .download import extract_compressed_file as extract_file
20
21
from ._get_input import get_input_mode
21
22
from fosslight_util .set_log import init_log
22
23
from fosslight_util .timer_thread import TimerThread
@@ -315,6 +316,7 @@ def run_main(mode_list, path_arg, dep_arguments, output_file_or_dir, file_format
315
316
default_oss_version = ""
316
317
src_path = ""
317
318
_executed_path = os .getcwd ()
319
+ extract_folder = ""
318
320
319
321
mode_not_supported = list (set (mode_list ).difference (SCANNER_MODE ))
320
322
if mode_not_supported :
@@ -337,6 +339,17 @@ def run_main(mode_list, path_arg, dep_arguments, output_file_or_dir, file_format
337
339
if isinstance (path_arg , list ):
338
340
if len (path_arg ) == 1 :
339
341
src_path = path_arg [0 ]
342
+
343
+ for ext in compression_extension :
344
+ if src_path .endswith (ext ):
345
+ temp_folder = f"temp_extract_{ datetime .now ().strftime ('%Y%m%d_%H%M%S' )} "
346
+ Path (temp_folder ).mkdir (parents = True , exist_ok = True )
347
+
348
+ extract_success = extract_file (src_path , temp_folder , False )
349
+ if extract_success :
350
+ src_path = os .path .join (_executed_path , temp_folder )
351
+ extract_folder = src_path
352
+ break
340
353
else :
341
354
logger .warning (f"Cannot analyze with multiple path: { path_arg } " )
342
355
@@ -414,6 +427,9 @@ def run_main(mode_list, path_arg, dep_arguments, output_file_or_dir, file_format
414
427
output_extension , num_cores , db_url ,
415
428
default_oss_name , default_oss_version , url_to_analyze ,
416
429
correct_mode , correct_fpath , ui_mode , path_to_exclude )
430
+
431
+ if extract_folder :
432
+ shutil .rmtree (extract_folder )
417
433
else :
418
434
logger .error ("No mode has been selected for analysis." )
419
435
try :
0 commit comments