#! /usr/bin/env python """ lserrs.py -- Build tool. Summarize errors from an error log.""" import os import re import sys # # Important constants. # _max_messages = 600 _max_loglines = 5000 def _scan_for_errors (filename, regexlist): """Find the error summary lines in a file.""" linecnt = 0 errcnt = 0 errlines = [] errs_by_phase = {} phaselist = [] phase = "unknown" f = open (filename, "r") for line in f.xreadlines (): if line[-1] == "\n": line = line[:-1] linecnt = linecnt + 1 if linecnt > _max_loglines: print "ERROR: %d lines seen, skipping rest: %s" % (_max_loglines, filename,) break #errlines = errlines + [line] if line[0:8] == "#----- (": #print "line:", line try: (junk, phase, pkgname, pkgver) = line.split (None, 3) except Exception: try: (junk, phase, pkgname) = line.split (None, 2) except Exception: phase = "unknown" print "ERROR: malformed error log header!" print "ERROR: filename: %s" % (filename,) print "ERROR: %s" % (line,) if phase[0] == "(": phase = phase[1:] phase = phase[:-1] #print "phase: '%s'" % (phase,) elif line[0:7] == "#----- ": #print "line:", line phase = "unknown" try: (junk, pkgname, pkgver) = line.split (None, 2) except Exception: try: (junk, pkgname) = line.split (None, 1) except Exception: print "ERROR: malformed error log header!" print "ERROR: filename: %s" % (filename,) print "ERROR:", line #print "phase: '%s'" % (phase,) #if phase in ["all", "codegen", "d0omgen", "include", "lib", "bin", "test"]: continue #if phase == "test": # print filename if line and (line[0] != "#"): matched = 0 for regex in regexlist: if regex.search (line): matched = 1 break if not matched: errcnt = errcnt + 1 #if errs_by_phase.has_key (phase): # errs_by_phase[phase] = errs_by_phase[phase] + [line] #else: # errs_by_phase[phase] = [line] # phaselist = phaselist + [phase] print line f.close () return (errcnt, errlines, errs_by_phase, phaselist) def _main (): # # Check environment variables. # pub = os.environ.get ("SRT_PUBLIC_CONTEXT") if not pub: print "ERROR: SRT_PUBLIC_CONTEXT is not set!" sys.exit (127) pri = os.environ.get ("SRT_PRIVATE_CONTEXT") if not pri: print "ERROR: SRT_PRIVATE_CONTEXT is not set!" sys.exit (127) # # Construct important directory names. # prireldbdir = os.path.join (pri, "D0reldb") pubreldbdir = os.path.join (pub, "D0reldb") # # Locate important files. # regexfil = os.path.join (prireldbdir, "errs.regex") if not os.path.isfile (regexfil): regexfil = os.path.join (pubreldbdir, "errs.regex") if not os.path.isfile (regexfil): print "ERROR: Could not find errs.regex!" sys.exit (127) # # Get regular expressions for error log filtering. # regexlist = [] f = open (regexfil, "r") for line in f.xreadlines (): if line[-1] == "\n": line = line[:-1] regexlist = regexlist + [re.compile (line)] f.close () # # Loop over error log files and print error summaries. # for infile in sys.argv[1:]: errlines = [] errs_by_phase = {} phaselist = [] errcnt = 0 if os.path.isfile (infile): print "#" print "#-----<%s>-----" % (infile,) print "#" (errcnt, errlines, errs_by_phase, phaselist) = _scan_for_errors (infile, regexlist) #if not errcnt: continue #if 0 == 1: # print "phases:" # for phase in phaselist: # print phase # for phase in phaselist: # print "%s:" % (phase,) # for line in errs_by_phase[phase]: # print line # print "errlines:" # for line in errlines: # print line #for phase in phaselist: # for line in errs_by_phase[phase]: # print line if __name__ == "__main__": # We are being run as a script. _main () sys.exit (0) else: # We are being loaded as a module. pass