1515from reuse ._main import parser as reuse_arg_parser
1616
1717_PKG_NAME = "fosslight_reuse"
18- _auto_add_mode = False
1918_result_log = {}
2019logger = logging .getLogger (constant .LOGGER_NAME )
2120
@@ -68,12 +67,39 @@ def check_input_format(input_copyright):
6867 check_ok = True
6968
7069 if regex .match (input_copyright ) is None :
71- logger .warning (" You have to input with following format - ' Copyright <year> <name>' " )
70+ logger .warning (" You have to input with following format - Copyright <year> <name>" )
7271 check_ok = False
7372
7473 return check_ok
7574
7675
76+ def input_license_while_running ():
77+ input_license = ""
78+
79+ logger .info ("# Select a license to write in the license missing files " )
80+ select = input (" 1.MIT, 2.Apache-2.0, 3.LGE-Proprietary, 4.Manaully Input, 5.Not select now : " )
81+ if select == '1' or select == 'MIT' :
82+ input_license = 'MIT'
83+ elif select == '2' or select == 'Apache-2.0' :
84+ input_license = 'Apache-2.0'
85+ elif select == '3' or select == 'LGE Proprietary License' :
86+ input_license = 'LicenseRef-LGE-Proprietary'
87+ elif select == '4' or select == 'Manually Input' :
88+ input_license = input (" ## Input your License : " )
89+ elif select == '5' or select == 'Quit' or select == 'quit' :
90+ logger .info (" Not selected any license to write " )
91+ return input_license
92+
93+
94+ def input_copyright_while_running ():
95+ input_copyright = ""
96+ input_copyright = input ("# Input Copyright to write in the copyright missing files (ex, Copyright <year> <name>) : " )
97+ if input_copyright == 'Quit' or input_copyright == 'quit' or input_copyright == 'Q' :
98+ return
99+
100+ return input_copyright
101+
102+
77103def set_missing_license_copyright (missing_license_filtered , missing_copyright_filtered , project , path_to_find , license , copyright ):
78104 input_license = None
79105 input_copyright = None
@@ -85,33 +111,17 @@ def set_missing_license_copyright(missing_license_filtered, missing_copyright_fi
85111
86112 # Print missing license
87113 if missing_license_filtered is not None and len (missing_license_filtered ) > 0 :
88- input_str = ""
89114 missing_license_list = []
90115
91116 logger .info ("# Missing license File(s) " )
92117 for lic_file in sorted (missing_license_filtered ):
93118 logger .info (f" * { lic_file } " )
94119 missing_license_list .append (path_to_find + '/' + lic_file )
95120
96- if _auto_add_mode :
97- # Automatic add mode
98- input_license = license
121+ if license == "" and copyright == "" :
122+ input_license = input_license_while_running ()
99123 else :
100- # Manual add Mode
101- logger .info ("# Select a license to write in the license missing files " )
102- select = input (" 1.MIT, 2.Apache-2.0, 3.LGE-Proprietary, 4.Manaully Input, 5.Not select now : " )
103- if select == '1' or select == 'MIT' :
104- input_license = 'MIT'
105- elif select == '2' or select == 'Apache-2.0' :
106- input_license = 'Apache-2.0'
107- elif select == '3' or select == 'LGE Proprietary License' :
108- input_license = 'LicenseRef-LGE-Proprietary'
109- elif select == '4' or select == 'Manually Input' :
110- input_str = input (" ## Input your License : " )
111- input_license = input_str
112- elif select == '5' or select == 'Quit' or select == 'quit' :
113- logger .info (" Not selected any license to write " )
114- return
124+ input_license = license
115125
116126 if input_license != "" :
117127 logger .warning (f" * Your input license : { input_license } " )
@@ -130,18 +140,14 @@ def set_missing_license_copyright(missing_license_filtered, missing_copyright_fi
130140 logger .info (f" * { cop_file } " )
131141 missing_copyright_list .append (os .getcwd () + '/' + path_to_find + '/' + cop_file )
132142
133- if _auto_add_mode :
134- # Automatic add mode
135- input_copyright = copyright
136- else :
137- # Manual add Mode
138- input_copyright = input ("# Input Copyright to write in the copyright missing files (ex, 'Copyright <year> <name>'') : " )
139- if input_copyright == 'Quit' or input_copyright == 'quit' or input_copyright == 'Q' :
140- return
143+ if license == "" and copyright == "" :
144+ input_copyright = input_copyright_while_running ()
141145
142146 input_ok = check_input_format (input_copyright )
143147 if input_ok is False :
144148 return
149+ else :
150+ input_copyright = copyright
145151
146152 if input_copyright != "" :
147153 logger .warning (f" * Your input Copyright : { input_copyright } " )
@@ -178,10 +184,9 @@ def save_result_log():
178184 logger .warning ("Failed to print add result log. " + str (ex ))
179185
180186
181- def add_content (path_to_find , file , manual_mode , input_license = "" , input_copyright = "" ):
182- global _auto_add_mode , _result_log
187+ def add_content (path_to_find , file , input_license = "" , input_copyright = "" ):
188+ global _result_log
183189 file_to_check_list = []
184- _auto_add_mode = False
185190 _check_only_file_mode = False
186191
187192 if path_to_find == "" :
@@ -192,7 +197,7 @@ def add_content(path_to_find, file, manual_mode, input_license="", input_copyrig
192197 logger , _result_log = init_log (os .path .join (output_dir , "fosslight_reuse_add_log_" + now + ".txt" ),
193198 True , logging .INFO , logging .DEBUG , _PKG_NAME , path_to_find )
194199
195- if input_copyright != "" and manual_mode is False :
200+ if input_copyright != "" :
196201 input_ok = check_input_format (input_copyright )
197202 if input_ok is False :
198203 return
@@ -201,30 +206,31 @@ def add_content(path_to_find, file, manual_mode, input_license="", input_copyrig
201206 file_to_check_list = file .split (',' )
202207 _check_only_file_mode = True
203208
204- if not manual_mode and _check_only_file_mode is False :
205- if input_license == "" and input_copyright == "" :
206- logger .info (" You have to input license and copyright to add with -l and -c option" )
207- return
208- _auto_add_mode = True
209-
210209 if _check_only_file_mode :
211210 main_parser = reuse_arg_parser ()
212-
213211 missing_license_list , missing_copyright_list , error_occurred , project = reuse_for_files (path_to_find , file_to_check_list )
214212
215213 if missing_license_list is not None and len (missing_license_list ) > 0 :
216- logger .warning (f" * Your input license : { input_license } " )
217- parsed_args = main_parser .parse_args (['addheader' , '--license' , str (input_license )] + missing_license_list )
218- try :
219- run (parsed_args , project )
220- except Exception as ex :
221- print_error ('Error_call_run_in_license_file_only :' + str (ex ))
214+ if input_license == "" and input_copyright == "" :
215+ input_license = input_license_while_running ()
216+
217+ if input_license != "" :
218+ logger .warning (f" * Your input license : { input_license } " )
219+ parsed_args = main_parser .parse_args (['addheader' , '--license' , str (input_license )] + missing_license_list )
220+ try :
221+ run (parsed_args , project )
222+ except Exception as ex :
223+ print_error ('Error_call_run_in_license_file_only :' + str (ex ))
222224
223225 if missing_copyright_list is not None and len (missing_copyright_list ) > 0 :
224- logger .warning (f" * Your input Copyright : { input_copyright } " )
225- parsed_args = main_parser .parse_args (['addheader' , '--copyright' ,
226- 'SPDX-FileCopyrightText: ' + str (input_copyright ),
227- '--exclude-year' ] + missing_copyright_list )
226+ if input_license == "" and input_copyright == "" :
227+ input_copyright = input_copyright_while_running ()
228+
229+ if input_copyright != "" :
230+ logger .warning (f" * Your input Copyright : { input_copyright } " )
231+ parsed_args = main_parser .parse_args (['addheader' , '--copyright' ,
232+ 'SPDX-FileCopyrightText: ' + str (input_copyright ),
233+ '--exclude-year' ] + missing_copyright_list )
228234 try :
229235 run (parsed_args , project )
230236 except Exception as ex :
0 commit comments