587
|
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 |
import StringIO
|
|
48 |
|
|
49 |
# Uncomment this line to enable logging in this module, or configure logging elsewhere
|
|
50 |
#logging.basicConfig(level=logging.DEBUG)
|
|
51 |
_logger = logging.getLogger('symbian.log')
|
|
52 |
|
|
53 |
class Parser(object):
|
|
54 |
""" Generic Symbian log parser. You just need to derive that class an override few methods
|
|
55 |
from the interface to implement your own functionnalities.
|
|
56 |
"""
|
|
57 |
|
|
58 |
def __init__(self, fileobject):
|
|
59 |
""" The constructor, it accepts a file object:
|
|
60 |
parser = Parser(open('output.log', 'r'))
|
|
61 |
"""
|
|
62 |
self.__file = fileobject
|
|
63 |
|
|
64 |
def parse(self):
|
588
|
65 |
""" Function that run the parsing of the log.
|
587
|
66 |
"""
|
|
67 |
#=== Stage=1 started Fri Apr 18 21:09:55 2008
|
|
68 |
match_stage = re.compile(r"===\s+(?:Stage=)?(.+)\s+(started|finished)\s+(.+)")
|
|
69 |
|
|
70 |
# === Stage=1 == ncp_psw
|
|
71 |
match_component_start = re.compile(r"===\s+(?:Stage=)?(.+?)\s+==\s+(.+)")
|
588
|
72 |
match_component_finished = re.compile(r"\+\+\s+Finished\s+at")
|
587
|
73 |
# === Stage=1 == ncp_psw
|
|
74 |
match_component_cmdline = re.compile(r"--\s+(.+)")
|
|
75 |
match_component_chdir = re.compile(r"Chdir\s+(.+)|cd\s+(.*?)\s+.*")
|
|
76 |
component_name = None
|
|
77 |
cmdline = None
|
|
78 |
chdir = None
|
|
79 |
content = StringIO.StringIO()
|
|
80 |
|
|
81 |
# parsing the content
|
|
82 |
for line in self.__file:
|
|
83 |
line = line.strip()
|
|
84 |
_logger.debug(line)
|
|
85 |
if component_name == None:
|
588
|
86 |
_logger.debug("Searching stage")
|
|
87 |
m_match = match_stage.match(line)
|
|
88 |
_logger.debug(m_match)
|
|
89 |
if m_match != None:
|
|
90 |
_logger.debug("Found stage %s, %s" % (m_match.group(2), m_match.group(3)))
|
|
91 |
if m_match.group(2) == "started":
|
|
92 |
self.start_stage(m_match.group(1), m_match.group(3))
|
587
|
93 |
else:
|
|
94 |
component_name = None
|
|
95 |
cmdline = None
|
|
96 |
chdir = None
|
|
97 |
content = StringIO.StringIO()
|
588
|
98 |
self.end_stage(m_match.group(1), m_match.group(3))
|
587
|
99 |
else:
|
|
100 |
_logger.debug("Searching for component")
|
588
|
101 |
m_match = match_component_start.match(line)
|
|
102 |
if m_match != None:
|
|
103 |
_logger.debug("Found component: %s" % m_match.group(2))
|
|
104 |
component_name = m_match.group(2)
|
587
|
105 |
else:
|
|
106 |
_logger.debug("Searching for component end")
|
588
|
107 |
m_match = match_component_finished.match(line)
|
|
108 |
if m_match != None:
|
587
|
109 |
self.task(component_name, cmdline, chdir, content.getvalue())
|
588
|
110 |
component_name = None
|
587
|
111 |
cmdline = None
|
|
112 |
chdir = None
|
588
|
113 |
content = StringIO.StringIO()
|
587
|
114 |
if cmdline == None:
|
|
115 |
_logger.debug("Searching for component command line")
|
588
|
116 |
m_match = match_component_cmdline.match(line)
|
|
117 |
if m_match != None:
|
|
118 |
_logger.debug("Found command line: %s" % m_match.group(1))
|
|
119 |
cmdline = m_match.group(1)
|
587
|
120 |
else:
|
|
121 |
_logger.debug("Searching for component dir")
|
|
122 |
if chdir == None:
|
588
|
123 |
m_match = match_component_chdir.match(line)
|
|
124 |
if m_match != None:
|
|
125 |
chdir = m_match.group(1)
|
587
|
126 |
if chdir == None:
|
588
|
127 |
chdir = m_match.group(2)
|
587
|
128 |
_logger.debug("Found dir: %s" % chdir)
|
|
129 |
continue
|
588
|
130 |
if not line.startswith("++ ") and not line.startswith("+++ "):
|
587
|
131 |
_logger.debug("Adding content")
|
|
132 |
content.write(line + "\n")
|
|
133 |
|
|
134 |
def start_stage(self, name, date):
|
|
135 |
""" Method to override to catch the start stage event. """
|
|
136 |
pass
|
|
137 |
|
|
138 |
def end_stage(self, name, date):
|
|
139 |
""" Method to override to catch the end stage event. """
|
|
140 |
pass
|
|
141 |
|
628
|
142 |
def task(self, name, cmdline, dir_, output):
|
587
|
143 |
""" Method to override to catch the task event. """
|
|
144 |
pass
|
|
145 |
|