66import sys
77import os
88import warnings
9- import getopt
109import logging
1110import copy
1211from datetime import datetime
2019from .run_scanoss import run_scanoss_py
2120from .run_scanoss import get_scanoss_extra_info
2221import yaml
22+ import argparse
2323
2424SCANOSS_SHEET_NAME = 'SRC_FL_Source'
2525SCANOSS_HEADER = {SCANOSS_SHEET_NAME : ['ID' , 'Source Name or Path' , 'OSS Name' ,
@@ -41,7 +41,6 @@ def main():
4141 success = True
4242 _result_log = {}
4343
44- argv = sys .argv [1 :]
4544 path_to_scan = os .getcwd ()
4645 write_json_file = False
4746 output_file_name = ""
@@ -53,31 +52,38 @@ def main():
5352 license_list = []
5453 time_out = 120
5554
56- try :
57- opts , args = getopt .getopt (argv , 'hvmjs:p:o:f:t:' )
58- for opt , arg in opts :
59- if opt == "-h" :
60- print_help_msg_source ()
61- elif opt == "-v" :
62- print_version (_PKG_NAME )
63- elif opt == "-p" :
64- path_to_scan = arg
65- if not path_to_scan :
66- path_to_scan = os .getcwd ()
67- elif opt == "-j" :
68- write_json_file = True
69- elif opt == "-o" :
70- output_file_name = arg
71- elif opt == "-m" :
72- print_matched_text = True
73- elif opt == "-f" :
74- format = arg
75- elif opt == "-s" :
76- selected_scanner = arg .lower ()
77- elif opt == "-t" :
78- time_out = arg
79- except Exception :
55+ parser = argparse .ArgumentParser (description = 'FOSSLight Source' , prog = 'fosslight_source' , add_help = False )
56+ parser .add_argument ('-h' , '--help' , action = 'store_true' , required = False )
57+ parser .add_argument ('-v' , '--version' , action = 'store_true' , required = False )
58+ parser .add_argument ('-p' , '--path' , nargs = 1 , type = str , required = False )
59+ parser .add_argument ('-j' , '--json' , action = 'store_true' , required = False )
60+ parser .add_argument ('-o' , '--output' , nargs = 1 , type = str , required = False , default = "" )
61+ parser .add_argument ('-m' , '--matched' , action = 'store_true' , required = False )
62+ parser .add_argument ('-f' , '--format' , nargs = 1 , type = str , required = False )
63+ parser .add_argument ('-s' , '--scanner' , nargs = 1 , type = str , required = False , default = 'all' )
64+ parser .add_argument ('-t' , '--timeout' , type = int , required = False , default = 120 )
65+
66+ args = parser .parse_args ()
67+
68+ if args .help :
8069 print_help_msg_source ()
70+ if args .version :
71+ print_version (_PKG_NAME )
72+ if not args .path :
73+ path_to_scan = os .getcwd ()
74+ else :
75+ path_to_scan = '' .join (args .path )
76+ if args .json :
77+ write_json_file = True
78+ output_file_name = '' .join (args .output )
79+ if args .matched :
80+ print_matched_text = True
81+ if args .format :
82+ format = '' .join (args .format )
83+ if args .scanner :
84+ selected_scanner = '' .join (args .scanner )
85+
86+ time_out = args .timeout
8187
8288 timer = TimerThread ()
8389 timer .setDaemon (True )
0 commit comments