buildframework/helium/tools/common/python/scripts/sbsscanlogmetadata.py
changeset 217 0f5e3a7fb6af
parent 179 d8ac696cc51f
child 587 85df38eb4012
equal deleted inserted replaced
181:59bb7c4d6172 217:0f5e3a7fb6af
     1 #============================================================================ 
     1 #============================================================================ 
     2 #Name        : filter_heliumlog.py 
     2 #Name        : sbsscanlogmetadata.py
     3 #Part of     : Helium 
     3 #Part of     : Helium 
     4 
     4 
     5 #Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
     5 #Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
     6 #All rights reserved.
     6 #All rights reserved.
     7 #This component and the accompanying materials are made available
     7 #This component and the accompanying materials are made available
    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 STREAM_REGEX =  {   "clean" : [r'<clean', r'</clean'],
    36 STREAM_REGEX =  {   "clean" : [r'<clean', r'</clean'],
    37                     "whatlog" : [r'<whatlog', r'</whatlog'],
    37                     "what" : [r'<whatlog', r'</whatlog'],
    38                     "warning" : [r'<warning', r'</warning']
    38                     "warning" : [r'<warning', r'</warning']
    39                 }
    39                 }
    40 
    40 
    41 class SBSScanlogMetadata(object):
    41 class SBSScanlogMetadata(object):
    42     """parses the raptor meatadata logs and separates the info out into HTML and XML logs for writing 
    42     """parses the raptor meatadata logs and separates the info out into HTML and XML logs for writing 
    43     to diamonds and other logs"""
    43     to diamonds and other logs"""
    44     
    44 
    45     def initializeLogPath(self):
    45     def initializeLogPath(self):
    46         index = self.logFileName.rfind(".")
    46         index = self.logFileName.rfind(".")
    47         if index < 0:
    47         if index < 0:
    48             index = len(self.logFileName)
    48             index = len(self.logFileName)
    49         for stream in STREAM_REGEX.keys():
    49         for stream in STREAM_REGEX.keys():
    50             self.stream_path[stream] = self.logFileName[:index] + "." + stream + \
    50             self.stream_path[stream] = self.logFileName[:index] + "." + stream + \
    51                         self.logFileName[index:]            
    51                         self.logFileName[index:]            
    52         if os.environ.has_key('SBS_CLEAN_LOG_FILE'):
    52         if os.environ.has_key('SBS_CLEAN_LOG_FILE'):
    53             self.stream_path['clean'] = os.environ['SBS_CLEAN_LOG_FILE']
    53             self.stream_path['clean'] = os.environ['SBS_CLEAN_LOG_FILE']
       
    54         if os.environ.has_key('SBS_WHAT_LOG_FILE'):
       
    55             self.stream_path['what'] = os.environ['SBS_WHAT_LOG_FILE']
    54             
    56             
    55     def initialize(self, logFile):
    57     def initialize(self, logFile):
    56         """Initialize helium log filter"""
    58         """Initialize helium log filter"""
    57         self.ignoreTextCompileObject = re.compile(IGNORE_TEXT_REG_EX);
    59         self.ignoreTextCompileObject = re.compile(IGNORE_TEXT_REG_EX);
    58         self.logFileName = str(logFile)
    60         self.logFileName = str(logFile)
    66         self.initializeLogPath()
    68         self.initializeLogPath()
    67         for stream in STREAM_REGEX.keys():
    69         for stream in STREAM_REGEX.keys():
    68             self.compiled_stream_object[stream] = []
    70             self.compiled_stream_object[stream] = []
    69             self.streams[stream] = open(self.stream_path[stream], "w")
    71             self.streams[stream] = open(self.stream_path[stream], "w")
    70             self.streamStatus[stream] = False
    72             self.streamStatus[stream] = False
       
    73             self.streams[stream].write(\
       
    74 """<?xml version="1.0" encoding="ISO-8859-1" ?>
       
    75 <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">""")
    71             for  searchString in STREAM_REGEX[stream]:
    76             for  searchString in STREAM_REGEX[stream]:
    72                 self.compiled_stream_object[stream].append(re.compile(searchString))
    77                 self.compiled_stream_object[stream].append(re.compile(searchString))
    73         return True
    78         return True
    74 
    79 
    75     def open(self, logFile):
    80     def open(self, logFile):
    83         for textLine in text.splitlines():
    88         for textLine in text.splitlines():
    84             textLine = textLine + '\n'
    89             textLine = textLine + '\n'
    85             if textLine.startswith("<?xml ") or textLine.startswith("<buildlog ") \
    90             if textLine.startswith("<?xml ") or textLine.startswith("<buildlog ") \
    86                 or textLine.startswith("</buildlog"):
    91                 or textLine.startswith("</buildlog"):
    87                 self.loggerout.write(textLine)
    92                 self.loggerout.write(textLine)
    88                 for stream in stream_list:
       
    89                     self.streams[stream].write(textLine)
       
    90                 continue
    93                 continue
    91             if(self.ignoreTextCompileObject.search(textLine)):
    94             if(self.ignoreTextCompileObject.search(textLine)):
    92                 continue
    95                 continue
    93             for stream in stream_list:
    96             for stream in stream_list:
    94                 if( (not self.streamStatus[stream]) and self.compiled_stream_object[stream][0].search(textLine)!= None):
    97                 if( (not self.streamStatus[stream]) and self.compiled_stream_object[stream][0].search(textLine)!= None):
    97                     self.streams[stream].write(textLine)
   100                     self.streams[stream].write(textLine)
    98                     self.streamStatus[stream] = False
   101                     self.streamStatus[stream] = False
    99                     break
   102                     break
   100     
   103     
   101                 if(self.streamStatus[stream]):
   104                 if(self.streamStatus[stream]):
       
   105                     if textLine.startswith("<?xml ") or textLine.startswith("<buildlog ") \
       
   106                         or textLine.startswith("</buildlog"):
       
   107                         continue
   102                     self.streams[stream].write(textLine)
   108                     self.streams[stream].write(textLine)
   103                     break
   109                     break
   104 
   110 
   105             self.loggerout.write(textLine)
   111             self.loggerout.write(textLine)
   106         return True
   112         return True
   114         """Close the log file"""
   120         """Close the log file"""
   115 
   121 
   116         try:
   122         try:
   117             self.loggerout.close()
   123             self.loggerout.close()
   118             for stream in self.streams.keys():
   124             for stream in self.streams.keys():
       
   125                 self.streams[stream].write('</buildlog>')
   119                 self.streams[stream].close()
   126                 self.streams[stream].close()
   120             return True
   127             return True
   121         except:
   128         except:
   122             self.loggerout = None
   129             self.loggerout = None
   123             self.streams = None
   130             self.streams = None