1 #============================================================================ |
|
2 #Name : sbsscanlogmetadata.py |
|
3 #Part of : Helium |
|
4 |
|
5 #Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
6 #All rights reserved. |
|
7 #This component and the accompanying materials are made available |
|
8 #under the terms of the License "Eclipse Public License v1.0" |
|
9 #which accompanies this distribution, and is available |
|
10 #at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
11 # |
|
12 #Initial Contributors: |
|
13 #Nokia Corporation - initial contribution. |
|
14 # |
|
15 #Contributors: |
|
16 # |
|
17 #Description: |
|
18 #=============================================================================== |
|
19 """parses the raptor metadata logs and separates the info out into HTML and XML |
|
20 logs for writing to diamonds and other logs""" |
|
21 |
|
22 import os |
|
23 import sys |
|
24 import re |
|
25 import datetime |
|
26 from optparse import OptionParser |
|
27 |
|
28 |
|
29 IGNORE_TEXT_REG_EX = "warning: no newline at end of file" |
|
30 |
|
31 STREAM_REGEX = { "clean" : [r'<clean', r'</clean'], |
|
32 "what" : [r'<whatlog', r'</whatlog'], |
|
33 "warning" : [r'<warning', r'</warning'] |
|
34 } |
|
35 |
|
36 class SBSScanlogMetadata(object): |
|
37 """parses the raptor metadata logs and separates the info out into HTML and |
|
38 XML logs for writing to diamonds and other logs""" |
|
39 |
|
40 def initializeLogPath(self): |
|
41 """retrieve the log file names from the environment variables """ |
|
42 index = self.logFileName.rfind(".") |
|
43 if index < 0: |
|
44 index = len(self.logFileName) |
|
45 for stream in STREAM_REGEX.keys(): |
|
46 self.stream_path[stream] = self.logFileName[:index] + "." + stream + \ |
|
47 self.logFileName[index:] |
|
48 if os.environ.has_key('SBS_CLEAN_LOG_FILE'): |
|
49 self.stream_path['clean'] = os.environ['SBS_CLEAN_LOG_FILE'] |
|
50 if os.environ.has_key('SBS_WHAT_LOG_FILE'): |
|
51 self.stream_path['what'] = os.environ['SBS_WHAT_LOG_FILE'] |
|
52 |
|
53 def initialize(self, logFile): |
|
54 """Initialize helium log filter""" |
|
55 self.ignoreTextCompileObject = re.compile(IGNORE_TEXT_REG_EX); |
|
56 self.logFileName = str(logFile) |
|
57 self.streamStatus = {} |
|
58 self.streams = {} |
|
59 self.stream_path = {} |
|
60 self.start_time = datetime.datetime.now() |
|
61 self.loggerout = open(self.logFileName,"w") |
|
62 self.compiled_stream_object = {} |
|
63 print "logName: %s\n" % self.logFileName |
|
64 self.initializeLogPath() |
|
65 for stream in STREAM_REGEX.keys(): |
|
66 self.compiled_stream_object[stream] = [] |
|
67 self.streams[stream] = open(self.stream_path[stream], "w") |
|
68 self.streamStatus[stream] = False |
|
69 self.streams[stream].write(\ |
|
70 """<?xml version="1.0" encoding="ISO-8859-1" ?> |
|
71 <buildlog sbs_version="" xmlns="http://symbian.com/xml/build/log" xmlns:progress="http://symbian.com/xml/build/log/progress" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symbian.com/xml/build/log http://symbian.com/xml/build/log/1_0.xsd">""") |
|
72 for searchString in STREAM_REGEX[stream]: |
|
73 self.compiled_stream_object[stream].append(re.compile(searchString)) |
|
74 return True |
|
75 |
|
76 def open(self, logFile): |
|
77 """ open the log file""" |
|
78 self.logFileName = str(logFile) |
|
79 return self.initialize(logFile) |
|
80 |
|
81 |
|
82 def write(self, text): |
|
83 """ callback function which is to process the logs""" |
|
84 stream_list = STREAM_REGEX.keys() |
|
85 for textLine in text.splitlines(): |
|
86 textLine = textLine + '\n' |
|
87 if textLine.startswith("<?xml ") or textLine.startswith("<buildlog ") \ |
|
88 or textLine.startswith("</buildlog"): |
|
89 self.loggerout.write(textLine) |
|
90 continue |
|
91 if(self.ignoreTextCompileObject.search(textLine)): |
|
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 if textLine.startswith("<?xml ") or textLine.startswith("<buildlog ") \ |
|
103 or textLine.startswith("</buildlog"): |
|
104 continue |
|
105 self.streams[stream].write(textLine) |
|
106 break |
|
107 |
|
108 self.loggerout.write(textLine) |
|
109 return True |
|
110 |
|
111 def summary(self): |
|
112 """Write Summary""" |
|
113 sys.stdout.write("sbs: build log in %s\n" % str(self.logFileName)) |
|
114 return False |
|
115 |
|
116 def close(self): |
|
117 """Close the log file""" |
|
118 |
|
119 try: |
|
120 self.loggerout.close() |
|
121 for stream in self.streams.keys(): |
|
122 self.streams[stream].write('</buildlog>') |
|
123 self.streams[stream].close() |
|
124 return True |
|
125 except: |
|
126 self.loggerout = None |
|
127 self.streams = None |
|
128 return False |
|
129 |
|
130 if __name__ == "__main__": |
|
131 # standalone app |
|
132 _cli = OptionParser(usage="%prog [options]") |
|
133 _cli.add_option("--log", help="Raptor log file") |
|
134 _cli.add_option("--output", help="Raptor log file") |
|
135 |
|
136 _opts, _ = _cli.parse_args() |
|
137 if not _opts.log: |
|
138 _cli.print_help() |
|
139 sys.exit(-1) |
|
140 |
|
141 _sbsFilter = SBSScanlogMetadata() |
|
142 _sbsFilter.open(_opts.output) |
|
143 |
|
144 _logFile = open(_opts.log, 'r') |
|
145 |
|
146 for line in _logFile: |
|
147 _sbsFilter.write(line) |
|
148 |
|
149 _sbsFilter.summary() |
|
150 _sbsFilter.close() |
|