Package symbian :: Module log
[hide private]
[frames] | no frames]

Source Code for Module symbian.log

  1  #============================================================================  
  2  #Name        : log.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   
 20  """ 
 21  Library that support Symbiam log parsing: 
 22   
 23  ===------------------------------------------------- 
 24  === Stage=1 
 25  ===------------------------------------------------- 
 26  === Stage=1 started Fri Apr 18 21:09:55 2008 
 27  === Stage=1 == ncp_psw 
 28  -- xcopy *.*  \\ /F /R /Y /S 
 29  --- Client0 Executed ID 1 
 30  ++ Started at Fri Apr 18 21:09:55 2008 
 31  +++ HiRes Start 1208542195.09307 
 32  Chdir \\psw\\ncp_psw\\psw 
 33  S:\\psw\\ncp_psw\\psw\\s60\\tools\\customizationtool\\ct.ini -> S:\\s60\\tools\\customizationtool\\ct.ini 
 34  S:\\psw\\ncp_psw\\psw\\s60\\tools\\customizationtool\\xml_data\\NCPAudioEqualizer_settings.xml -> S:\\s60\\tools\\customizationtool\\xml_data\\NCPAudioEqualizer_settings.xml 
 35  S:\\psw\\ncp_psw\\psw\\s60\\tools\\customizationtool\\xml_data\\NCPHWGeneral_settings.xml -> S:\\s60\\tools\\customizationtool\\xml_data\\NCPHWGeneral_settings.xml 
 36  S:\\psw\\ncp_psw\\psw\\s60\\tools\\customizationtool\\xml_data\\NCPLight_settings.xml -> S:\\s60\\tools\\customizationtool\\xml_data\\NCPLight_settings.xml 
 37  S:\\psw\\ncp_psw\\psw\\s60\\tools\\customizationtool\\xml_data\\NCPSysAp_settings.xml -> S:\\s60\\tools\\customizationtool\\xml_data\\NCPSysAp_settings.xml 
 38  S:\\psw\\ncp_psw\\psw\\s60\\tools\\customizationtool\\xml_data\\VariantFeatures.xml -> S:\\s60\\tools\\customizationtool\\xml_data\\VariantFeatures.xml 
 39  6 File(s) copied 
 40  +++ HiRes End 1208542195.28056 
 41  ++ Finished at Fri Apr 18 21:09:55 2008 
 42  === Stage=1 finished Fri Apr 18 21:09:55 2008 
 43  ... 
 44  """ 
 45  import re 
 46  import logging 
 47   
 48  # Uncomment this line to enable logging in this module, or configure logging elsewhere 
 49  #logging.basicConfig(level=logging.DEBUG) 
 50  _logger = logging.getLogger('symbian.log') 
 51   
52 -class Parser(object):
53 """ Generic Symbian log parser. You just need to derive that class an override few methods 54 from the interface to implement your own functionnalities. 55 """ 56
57 - def __init__(self, fileobject):
58 """ The constructor, it accepts a file object: 59 parser = Parser(open('output.log', 'r')) 60 """ 61 self.__file = fileobject
62
63 - def parse(self):
64 """ Function that run the parsing of the log. 65 """ 66 #=== Stage=1 started Fri Apr 18 21:09:55 2008 67 match_stage = re.compile(r"===\s+(?:Stage=)?(.+)\s+(started|finished)\s+(.+)") 68 69 # === Stage=1 == ncp_psw 70 match_component_start = re.compile(r"===\s+(?:Stage=)?(.+?)\s+==\s+(.+)") 71 match_component_finished = re.compile(r"\+\+\s+Finished\s+at") 72 # === Stage=1 == ncp_psw 73 match_component_cmdline = re.compile(r"--\s+(.+)") 74 match_component_chdir = re.compile(r"Chdir\s+(.+)|cd\s+(.*?)\s+.*") 75 component_name = None 76 cmdline = None 77 chdir = None 78 content = "" 79 80 # parsing the content 81 for line in self.__file: 82 line = line.strip() 83 _logger.debug(line) 84 if component_name == None: 85 _logger.debug("Searching stage") 86 m = match_stage.match(line) 87 _logger.debug(m) 88 if m != None: 89 _logger.debug("Found stage %s, %s" % (m.group(2), m.group(3))) 90 if m.group(2) == "started": 91 self.start_stage(m.group(1), m.group(3)) 92 else: 93 component_name = None 94 cmdline = None 95 chdir = None 96 content = "" 97 self.end_stage(m.group(1), m.group(3)) 98 else: 99 _logger.debug("Searching for component") 100 m = match_component_start.match(line) 101 if m != None: 102 _logger.debug("Found component: %s" % m.group(2)) 103 component_name = m.group(2) 104 else: 105 _logger.debug("Searching for component end") 106 m = match_component_finished.match(line) 107 if m != None: 108 self.task(component_name, cmdline, chdir, content) 109 component_name = None 110 cmdline = None 111 chdir = None 112 content = "" 113 if cmdline == None: 114 _logger.debug("Searching for component command line") 115 m = match_component_cmdline.match(line) 116 if m != None: 117 _logger.debug("Found command line: %s" % m.group(1)) 118 cmdline = m.group(1) 119 else: 120 _logger.debug("Searching for component dir") 121 if chdir == None: 122 m = match_component_chdir.match(line) 123 if m != None: 124 chdir = m.group(1) 125 if chdir == None: 126 chdir = m.group(2) 127 _logger.debug("Found dir: %s" % chdir) 128 continue 129 if not line.startswith("++ ") and not line.startswith("+++ "): 130 _logger.debug("Adding content") 131 content += line + "\n"
132
133 - def start_stage(self, name, date):
134 """ Method to override to catch the start stage event. """ 135 pass
136
137 - def end_stage(self, name, date):
138 """ Method to override to catch the end stage event. """ 139 pass
140
141 - def task(self, name, cmdline, dir, output):
142 """ Method to override to catch the task event. """ 143 pass
144