@@ -590,58 +590,55 @@ def parse_log_for_error(txt, regExp=None, stdout=True, msg=None):
590590
591591 return res
592592
593-
594- def check_log_for_errors (logTxt , regExps ):
593+ def extract_errors_from_log (log_txt , reg_exps ):
595594 """
596- Check logTxt for messages matching regExps in order and do appropriate action
597- :param logTxt : String containing the log, will be split into individual lines
598- :param regExps : List of: regular expressions (as RE or string ) to error on,
595+ Check log_txt for messages matching regExps and return warnings and errors
596+ :param log_txt : String containing the log, will be split into individual lines
597+ :param reg_exps : List of: regular expressions (as strings ) to error on,
599598 or tuple of regular expression and action (any of [IGNORE, WARN, ERROR])
599+ :return (warnings, errors) as lists of lines containing a match
600600 """
601- global errors_found_in_log
602-
603- def is_regexp_object (objToTest ):
604- try :
605- objToTest .match ('' )
606- return True
607- except AttributeError :
608- return False
609601
610602 # Avoid accidentally passing a single element
611- assert isinstance (regExps , list ), "regExps must be a list"
612- regExpTuples = []
613- for cur in regExps :
603+ assert isinstance (reg_exps , list ), "reg_exps must be a list"
604+ re_tuples = []
605+ for cur in reg_exps :
614606 try :
615607 if isinstance (cur , str ):
616- regExpTuples .append ((re .compile (cur ), ERROR ))
617- elif is_regexp_object (cur ):
618- regExpTuples .append ((cur , ERROR ))
619- elif len (cur ) != 2 :
620- raise TypeError ("Invalid tuple" )
621- elif not isinstance (cur [0 ], str ) and not is_regexp_object (cur [0 ]):
622- raise TypeError ("Invalid RegExp in tuple" )
623- elif cur [1 ] not in (IGNORE , WARN , ERROR ):
624- raise TypeError ("Invalid action in tuple" )
608+ reg_exp , action = cur , ERROR
625609 else :
626- regExpTuples .append ((re .compile (cur [0 ]) if isinstance (cur [0 ], str ) else cur [0 ], cur [1 ]))
627- except TypeError :
628- raise EasyBuildError ("Invalid input: No RegExp or tuple of RegExp and action: %s" % str (cur ))
610+ reg_exp , action = cur
611+ if not isinstance (reg_exp , str ) or action not in (IGNORE , WARN , ERROR ):
612+ raise TypeError ("Invalid types" )
613+ re_tuples .append ((re .compile (reg_exp ), action ))
614+ except Exception as e :
615+ raise EasyBuildError ("Invalid input: No RegExp or tuple of RegExp and action '%s' (%s)" , str (cur ), e )
629616 warnings = []
630617 errors = []
631- for l in logTxt .split ('\n ' ):
632- for regExp , action in regExpTuples :
633- m = regExp .search (l )
634- if m :
618+ for line in log_txt .split ('\n ' ):
619+ for reg_exp , action in re_tuples :
620+ if reg_exp .search (line ):
635621 if action == ERROR :
636- errors .append (l )
622+ errors .append (line )
637623 elif action == WARN :
638- warnings .append (l )
624+ warnings .append (line )
639625 break
626+ return warnings , errors
627+
628+ def check_log_for_errors (log_txt , reg_exps ):
629+ """
630+ Check log_txt for messages matching regExps in order and do appropriate action
631+ :param log_txt: String containing the log, will be split into individual lines
632+ :param reg_exps: List of: regular expressions (as strings) to error on,
633+ or tuple of regular expression and action (any of [IGNORE, WARN, ERROR])
634+ """
635+ global errors_found_in_log
636+ warnings , errors = extract_errors_from_log (log_txt , reg_exps )
637+
640638 errors_found_in_log += len (warnings ) + len (errors )
641639 if warnings :
642- _log .warning ("Found %s potential errors in command output (output: %s)" %
643- ( len (warnings ), ", " .join (warnings ) ))
640+ _log .warning ("Found %s potential error(s) in command output (output: %s)" ,
641+ len (warnings ), ", " .join (warnings ))
644642 if errors :
645- raise EasyBuildError ("Found %s errors in command output (output: %s)" %
646- (len (errors ), ", " .join (errors )))
647-
643+ raise EasyBuildError ("Found %s error(s) in command output (output: %s)" ,
644+ len (errors ), ", " .join (errors ))
0 commit comments