2727import re
2828from typing import Tuple
2929import urllib .parse
30+ import json
3031
3132logger = logging .getLogger (constant .LOGGER_NAME )
3233compression_extension = {".tar.bz2" , ".tar.gz" , ".tar.xz" , ".tgz" , ".tar" , ".zip" , ".jar" , ".bz2" }
@@ -96,7 +97,8 @@ def parse_src_link(src_link):
9697def cli_download_and_extract (link : str , target_dir : str , log_dir : str , checkout_to : str = "" ,
9798 compressed_only : bool = False , ssh_key : str = "" ,
9899 id : str = "" , git_token : str = "" ,
99- called_cli : bool = True ) -> Tuple [bool , str , str , str ]:
100+ called_cli : bool = True ,
101+ output : bool = False ) -> Tuple [bool , str , str , str ]:
100102 global logger
101103
102104 success = True
@@ -155,6 +157,17 @@ def cli_download_and_extract(link: str, target_dir: str, log_dir: str, checkout_
155157 success = False
156158 msg = str (error )
157159
160+ if output :
161+ output_result = {
162+ "success" : success ,
163+ "message" : msg ,
164+ "oss_name" : oss_name ,
165+ "oss_version" : oss_version
166+ }
167+ output_json = os .path .join (log_dir , "fosslight_download_output.json" )
168+ with open (output_json , 'w' ) as f :
169+ json .dump (output_result , f , indent = 4 )
170+
158171 logger .info (f"\n * FOSSLight Downloader - Result: { success } ({ msg } )" )
159172 return success , msg , oss_name , oss_version
160173
@@ -478,10 +491,17 @@ def main():
478491 parser .add_argument ('-s' , '--source' , help = 'Source link to download' , type = str , dest = 'source' )
479492 parser .add_argument ('-t' , '--target_dir' , help = 'Target directory' , type = str , dest = 'target_dir' , default = "" )
480493 parser .add_argument ('-d' , '--log_dir' , help = 'Directory to save log file' , type = str , dest = 'log_dir' , default = "" )
494+ parser .add_argument ('-c' , '--checkout_to' , help = 'Checkout to branch or tag' , type = str , dest = 'checkout_to' , default = "" )
495+ parser .add_argument ('-z' , '--compressed_only' , help = 'Unzip only compressed file' ,
496+ action = 'store_true' , dest = 'compressed_only' , default = False )
497+ parser .add_argument ('-o' , '--output' , help = 'Generate output file' , action = 'store_true' , dest = 'output' , default = False )
481498
482499 src_link = ""
483500 target_dir = os .getcwd ()
484501 log_dir = os .getcwd ()
502+ checkout_to = ""
503+ compressed_only = False
504+ output = False
485505
486506 try :
487507 args = parser .parse_args ()
@@ -496,11 +516,19 @@ def main():
496516 target_dir = args .target_dir
497517 if args .log_dir :
498518 log_dir = args .log_dir
519+ if args .checkout_to :
520+ checkout_to = args .checkout_to
521+ if args .compressed_only :
522+ compressed_only = args .compressed_only
523+ if args .output :
524+ output = args .output
499525
500526 if not src_link :
501527 print_help_msg_download ()
502528 else :
503- cli_download_and_extract (src_link , target_dir , log_dir )
529+ cli_download_and_extract (src_link , target_dir , log_dir , checkout_to ,
530+ compressed_only , "" , "" , "" , False ,
531+ output )
504532
505533
506534if __name__ == '__main__' :
0 commit comments