31 from optparse import OptionParser |
31 from optparse import OptionParser |
32 |
32 |
33 |
33 |
34 IGNORE_TEXT_REG_EX = "warning: no newline at end of file" |
34 IGNORE_TEXT_REG_EX = "warning: no newline at end of file" |
35 |
35 |
36 WARNING_TAG = "<warning>.*</warning>" |
36 STREAM_REGEX = { "clean" : [r'<clean', r'</clean'], |
|
37 "whatlog" : [r'<whatlog', r'</whatlog'], |
|
38 "warning" : [r'<warning', r'</warning'] |
|
39 } |
37 |
40 |
38 class SBSScanlogMetadata(): |
41 class SBSScanlogMetadata(object): |
|
42 """parses the raptor meatadata logs and separates the info out into HTML and XML logs for writing |
|
43 to diamonds and other logs""" |
|
44 |
|
45 def initializeLogPath(self): |
|
46 index = self.logFileName.rfind(".") |
|
47 if index < 0: |
|
48 index = len(self.logFileName) |
|
49 for stream in STREAM_REGEX.keys(): |
|
50 self.stream_path[stream] = self.logFileName[:index] + "." + stream + \ |
|
51 self.logFileName[index:] |
|
52 if os.environ.has_key('SBS_CLEAN_LOG_FILE'): |
|
53 self.stream_path['clean'] = os.environ['SBS_CLEAN_LOG_FILE'] |
|
54 |
39 def initialize(self, logFile): |
55 def initialize(self, logFile): |
40 """Initialize helium log filter""" |
56 """Initialize helium log filter""" |
41 self.ignoreTextCompileObject = re.compile(IGNORE_TEXT_REG_EX); |
57 self.ignoreTextCompileObject = re.compile(IGNORE_TEXT_REG_EX); |
42 self.warningCompileObject = re.compile(WARNING_TAG); |
58 self.logFileName = str(logFile) |
43 self.startRecording = False |
59 self.streamStatus = {} |
44 self.logFileName = logFile |
60 self.streams = {} |
45 self.warningFileName = "%s%s" % (logFile, "exceptions.xml") |
61 self.stream_path = {} |
46 self.inReceipe = False |
|
47 self.start_time = datetime.datetime.now() |
62 self.start_time = datetime.datetime.now() |
48 self.loggerout = open(str(self.logFileName),"w") |
63 self.loggerout = open(self.logFileName,"w") |
49 self.warningout = open(str(self.warningFileName),"w") |
64 self.compiled_stream_object = {} |
50 print "logName: %s\n" % self.logFileName |
65 print "logName: %s\n" % self.logFileName |
|
66 self.initializeLogPath() |
|
67 for stream in STREAM_REGEX.keys(): |
|
68 self.compiled_stream_object[stream] = [] |
|
69 self.streams[stream] = open(self.stream_path[stream], "w") |
|
70 self.streamStatus[stream] = False |
|
71 for searchString in STREAM_REGEX[stream]: |
|
72 self.compiled_stream_object[stream].append(re.compile(searchString)) |
51 return True |
73 return True |
52 |
74 |
53 def open(self, logFile): |
75 def open(self, logFile): |
54 self.logFileName = logFile |
76 self.logFileName = str(logFile) |
55 self.initialize(logFile) |
77 return self.initialize(logFile) |
56 |
78 |
57 |
79 |
58 def write(self, text): |
80 def write(self, text): |
59 """ callback function which is to process the logs""" |
81 """ callback function which is to process the logs""" |
|
82 stream_list = STREAM_REGEX.keys() |
60 for textLine in text.splitlines(): |
83 for textLine in text.splitlines(): |
61 textLine = textLine + '\n' |
84 textLine = textLine + '\n' |
|
85 if textLine.startswith("<?xml ") or textLine.startswith("<buildlog ") \ |
|
86 or textLine.startswith("</buildlog"): |
|
87 self.loggerout.write(textLine) |
|
88 for stream in stream_list: |
|
89 self.streams[stream].write(textLine) |
|
90 continue |
62 if(self.ignoreTextCompileObject.search(textLine)): |
91 if(self.ignoreTextCompileObject.search(textLine)): |
63 continue |
92 continue |
|
93 for stream in stream_list: |
|
94 if( (not self.streamStatus[stream]) and self.compiled_stream_object[stream][0].search(textLine)!= None): |
|
95 self.streamStatus[stream] = True |
|
96 if (self.streamStatus[stream] and self.compiled_stream_object[stream][1].search(textLine)!= None): |
|
97 self.streams[stream].write(textLine) |
|
98 self.streamStatus[stream] = False |
|
99 break |
|
100 |
|
101 if(self.streamStatus[stream]): |
|
102 self.streams[stream].write(textLine) |
|
103 break |
64 |
104 |
65 #only temporary until the fix for special character handling from raptor is available |
|
66 if(self.warningCompileObject.search(textLine)): |
|
67 self.warningout.write(textLine + "\n") |
|
68 continue |
|
69 self.loggerout.write(textLine) |
105 self.loggerout.write(textLine) |
70 return True |
106 return True |
71 |
107 |
72 def summary(self): |
108 def summary(self): |
73 """Write Summary""" |
109 """Write Summary""" |