@@ -591,57 +591,56 @@ def parse_log_for_error(txt, regExp=None, stdout=True, msg=None):
591591 return res
592592
593593
594- def check_log_for_errors ( logTxt , regExps ):
594+ def extract_errors_from_log ( log_txt , reg_exps ):
595595 """
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,
596+ Check log_txt for messages matching regExps and return warnings and errors
597+ :param log_txt : String containing the log, will be split into individual lines
598+ :param reg_exps : List of: regular expressions (as strings ) to error on,
599599 or tuple of regular expression and action (any of [IGNORE, WARN, ERROR])
600+ :return (warnings, errors) as lists of lines containing a match
600601 """
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
609602
610603 # Avoid accidentally passing a single element
611- assert isinstance (regExps , list ), "regExps must be a list"
612- regExpTuples = []
613- for cur in regExps :
604+ assert isinstance (reg_exps , list ), "reg_exps must be a list"
605+ re_tuples = []
606+ for cur in reg_exps :
614607 try :
615608 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" )
609+ reg_exp , action = cur , ERROR
625610 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 ))
611+ reg_exp , action = cur
612+ if not isinstance (reg_exp , str ) or action not in (IGNORE , WARN , ERROR ):
613+ raise TypeError ("Invalid types" )
614+ re_tuples .append ((re .compile (reg_exp ), action ))
615+ except Exception as e :
616+ raise EasyBuildError ("Invalid input: No RegExp or tuple of RegExp and action '%s' (%s)" , str (cur ), e )
629617 warnings = []
630618 errors = []
631- for l in logTxt .split ('\n ' ):
632- for regExp , action in regExpTuples :
633- m = regExp .search (l )
634- if m :
619+ for line in log_txt .split ('\n ' ):
620+ for reg_exp , action in re_tuples :
621+ if reg_exp .search (line ):
635622 if action == ERROR :
636- errors .append (l )
623+ errors .append (line )
637624 elif action == WARN :
638- warnings .append (l )
625+ warnings .append (line )
639626 break
627+ return warnings , errors
628+
629+
630+ def check_log_for_errors (log_txt , reg_exps ):
631+ """
632+ Check log_txt for messages matching regExps in order and do appropriate action
633+ :param log_txt: String containing the log, will be split into individual lines
634+ :param reg_exps: List of: regular expressions (as strings) to error on,
635+ or tuple of regular expression and action (any of [IGNORE, WARN, ERROR])
636+ """
637+ global errors_found_in_log
638+ warnings , errors = extract_errors_from_log (log_txt , reg_exps )
639+
640640 errors_found_in_log += len (warnings ) + len (errors )
641641 if warnings :
642- _log .warning ("Found %s potential errors in command output (output: %s)" %
643- ( len (warnings ), ", " .join (warnings ) ))
642+ _log .warning ("Found %s potential error(s) in command output (output: %s)" ,
643+ len (warnings ), ", " .join (warnings ))
644644 if errors :
645- raise EasyBuildError ("Found %s errors in command output (output: %s)" %
646- (len (errors ), ", " .join (errors )))
647-
645+ raise EasyBuildError ("Found %s error(s) in command output (output: %s)" ,
646+ len (errors ), ", " .join (errors ))
0 commit comments