@@ -170,16 +170,68 @@ def on_import_task_start(self, task, session):
170170 if checks_failed :
171171 task ._badfiles_checks_failed = checks_failed
172172
173+ def handle_import_action (self , action , failure_type ):
174+ if action == "abort" :
175+ ui .print_ (
176+ f"{ ui .colorize ('text_warning' , 'Aborting' )} "
177+ f" due to import_action_on_{ failure_type } configuration"
178+ )
179+ raise importer .ImportAbortError ()
180+ elif action == "skip" :
181+ ui .print_ (
182+ f"{ ui .colorize ('text_warning' , 'Skipping' )} "
183+ f" due to import_action_on_{ failure_type } configuration"
184+ )
185+ return importer .Action .SKIP
186+ elif action == "continue" :
187+ ui .print_ (
188+ f"{ ui .colorize ('text_warning' , 'Continuing' )} "
189+ f" due to import_action_on_{ failure_type } configuration"
190+ )
191+ return None
192+ else :
193+ ui .print_ (
194+ ui .colorize (
195+ "text_warning" ,
196+ f"Got invalid import_action_on_{ failure_type } "
197+ f" configuration: { action } " ,
198+ )
199+ )
200+ ui .print_ (
201+ ui .colorize (
202+ "text_warning" ,
203+ f"import_action_on_{ failure_type } should be one of:"
204+ f" ask abort skip continue" ,
205+ )
206+ )
207+ raise importer .ImportAbortError ()
208+
173209 def on_import_task_before_choice (self , task , session ):
174210 if hasattr (task , "_badfiles_checks_failed" ):
211+ warning_action = self .config ["import_action_on_warning" ].get ("ask" )
212+ error_action = self .config ["import_action_on_error" ].get ("ask" )
213+
175214 ui .print_ (
176215 f"{ ui .colorize ('text_warning' , 'BAD' )} one or more files failed"
177216 " checks:"
178217 )
218+
219+ found_warning = False
220+ found_error = False
179221 for error in task ._badfiles_checks_failed :
180222 for error_line in error :
223+ if "warning" in error_line .lower ():
224+ found_warning = True
225+ if "error" in error_line .lower ():
226+ found_error = True
227+
181228 ui .print_ (error_line )
182229
230+ if found_error and error_action != "ask" :
231+ return self .handle_import_action (error_action , "error" )
232+ elif found_warning and warning_action != "ask" :
233+ return self .handle_import_action (warning_action , "warning" )
234+
183235 ui .print_ ()
184236 ui .print_ ("What would you like to do?" )
185237
0 commit comments