buildframework/helium/sf/python/pythoncore/lib/symbian/log.py
author wbernard
Fri, 13 Aug 2010 14:59:05 +0300
changeset 628 7c4a911dc066
parent 588 c7c26511138f
permissions -rw-r--r--
helium_11.0.0-e00f171ca185
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     1
#============================================================================ 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     2
#Name        : log.py 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     3
#Part of     : Helium 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     4
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     5
#Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     6
#All rights reserved.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     7
#This component and the accompanying materials are made available
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     8
#under the terms of the License "Eclipse Public License v1.0"
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     9
#which accompanies this distribution, and is available
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    10
#at the URL "http://www.eclipse.org/legal/epl-v10.html".
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    11
#
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    12
#Initial Contributors:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    13
#Nokia Corporation - initial contribution.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    14
#
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    15
#Contributors:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    16
#
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    17
#Description:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    18
#===============================================================================
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    19
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    20
"""
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    21
Library that support Symbiam log parsing:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    22
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    23
===-------------------------------------------------
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    24
=== Stage=1
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    25
===-------------------------------------------------
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    26
=== Stage=1 started Fri Apr 18 21:09:55 2008
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    27
=== Stage=1 == ncp_psw
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    28
-- xcopy *.*  \\ /F /R /Y /S
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    29
--- Client0 Executed ID 1
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    30
++ Started at Fri Apr 18 21:09:55 2008
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    31
+++ HiRes Start 1208542195.09307
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    32
Chdir \\psw\\ncp_psw\\psw
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    33
S:\\psw\\ncp_psw\\psw\\s60\\tools\\customizationtool\\ct.ini -> S:\\s60\\tools\\customizationtool\\ct.ini
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    34
S:\\psw\\ncp_psw\\psw\\s60\\tools\\customizationtool\\xml_data\\NCPAudioEqualizer_settings.xml -> S:\\s60\\tools\\customizationtool\\xml_data\\NCPAudioEqualizer_settings.xml
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    35
S:\\psw\\ncp_psw\\psw\\s60\\tools\\customizationtool\\xml_data\\NCPHWGeneral_settings.xml -> S:\\s60\\tools\\customizationtool\\xml_data\\NCPHWGeneral_settings.xml
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    36
S:\\psw\\ncp_psw\\psw\\s60\\tools\\customizationtool\\xml_data\\NCPLight_settings.xml -> S:\\s60\\tools\\customizationtool\\xml_data\\NCPLight_settings.xml
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    37
S:\\psw\\ncp_psw\\psw\\s60\\tools\\customizationtool\\xml_data\\NCPSysAp_settings.xml -> S:\\s60\\tools\\customizationtool\\xml_data\\NCPSysAp_settings.xml
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    38
S:\\psw\\ncp_psw\\psw\\s60\\tools\\customizationtool\\xml_data\\VariantFeatures.xml -> S:\\s60\\tools\\customizationtool\\xml_data\\VariantFeatures.xml
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    39
6 File(s) copied
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    40
+++ HiRes End 1208542195.28056
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    41
++ Finished at Fri Apr 18 21:09:55 2008
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    42
=== Stage=1 finished Fri Apr 18 21:09:55 2008
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    43
...
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    44
"""
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    45
import re
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    46
import logging
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    47
import StringIO
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    48
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    49
# Uncomment this line to enable logging in this module, or configure logging elsewhere
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    50
#logging.basicConfig(level=logging.DEBUG)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    51
_logger = logging.getLogger('symbian.log')
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    52
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    53
class Parser(object):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    54
    """ Generic Symbian log parser. You just need to derive that class an override few methods
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    55
     from the interface to implement your own functionnalities.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    56
    """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    57
    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    58
    def __init__(self, fileobject):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    59
        """ The constructor, it accepts a file object:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    60
            parser = Parser(open('output.log', 'r'))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    61
        """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    62
        self.__file = fileobject
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    63
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    64
    def parse(self):
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    65
        """ Function that run the parsing of the log.
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    66
        """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    67
        #=== Stage=1 started Fri Apr 18 21:09:55 2008
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    68
        match_stage = re.compile(r"===\s+(?:Stage=)?(.+)\s+(started|finished)\s+(.+)")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    69
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    70
        # === Stage=1 == ncp_psw 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    71
        match_component_start = re.compile(r"===\s+(?:Stage=)?(.+?)\s+==\s+(.+)")
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    72
        match_component_finished = re.compile(r"\+\+\s+Finished\s+at")
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    73
        # === Stage=1 == ncp_psw 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    74
        match_component_cmdline = re.compile(r"--\s+(.+)")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    75
        match_component_chdir = re.compile(r"Chdir\s+(.+)|cd\s+(.*?)\s+.*")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    76
        component_name =  None
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    77
        cmdline =  None
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    78
        chdir =  None
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    79
        content = StringIO.StringIO()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    80
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    81
        # parsing the content
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    82
        for line in self.__file:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    83
            line = line.strip()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    84
            _logger.debug(line)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    85
            if component_name == None:
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    86
                _logger.debug("Searching stage")
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    87
                m_match = match_stage.match(line)
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    88
                _logger.debug(m_match)
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    89
                if m_match != None:
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    90
                    _logger.debug("Found stage %s, %s" % (m_match.group(2), m_match.group(3)))
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    91
                    if m_match.group(2) == "started":
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    92
                        self.start_stage(m_match.group(1), m_match.group(3))
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    93
                    else:                        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    94
                        component_name = None  
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    95
                        cmdline = None
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    96
                        chdir = None
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    97
                        content = StringIO.StringIO()
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    98
                        self.end_stage(m_match.group(1), m_match.group(3))
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    99
                else:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   100
                    _logger.debug("Searching for component")
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   101
                    m_match = match_component_start.match(line)
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   102
                    if  m_match != None:
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   103
                        _logger.debug("Found component: %s" % m_match.group(2))
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   104
                        component_name = m_match.group(2)
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   105
            else:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   106
                _logger.debug("Searching for component end")
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   107
                m_match = match_component_finished.match(line)
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   108
                if m_match != None:
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   109
                    self.task(component_name, cmdline, chdir, content.getvalue())
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   110
                    component_name = None
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   111
                    cmdline = None
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   112
                    chdir = None
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   113
                    content = StringIO.StringIO()
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   114
                if cmdline == None:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   115
                    _logger.debug("Searching for component command line")
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   116
                    m_match = match_component_cmdline.match(line)
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   117
                    if m_match != None:
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   118
                        _logger.debug("Found command line: %s" % m_match.group(1))
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   119
                        cmdline = m_match.group(1)
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   120
                else:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   121
                    _logger.debug("Searching for component dir")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   122
                    if chdir == None:
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   123
                        m_match = match_component_chdir.match(line)
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   124
                        if m_match != None:
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   125
                            chdir = m_match.group(1)
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   126
                            if chdir == None:
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   127
                                chdir = m_match.group(2)
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   128
                            _logger.debug("Found dir: %s" % chdir)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   129
                            continue
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   130
                    if not line.startswith("++ ") and not line.startswith("+++ "):
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   131
                        _logger.debug("Adding content")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   132
                        content.write(line + "\n")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   133
                
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   134
    def start_stage(self, name, date):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   135
        """ Method to override to catch the start stage event. """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   136
        pass
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   137
    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   138
    def end_stage(self, name, date):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   139
        """ Method to override to catch the end stage event. """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   140
        pass
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   141
    
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   142
    def task(self, name, cmdline, dir_, output):
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   143
        """ Method to override to catch the task event. """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   144
        pass
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   145