1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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
49
50 _logger = logging.getLogger('symbian.log')
51
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
58 """ The constructor, it accepts a file object:
59 parser = Parser(open('output.log', 'r'))
60 """
61 self.__file = fileobject
62
64 """ Function that run the parsing of the log.
65 """
66
67 match_stage = re.compile(r"===\s+(?:Stage=)?(.+)\s+(started|finished)\s+(.+)")
68
69
70 match_component_start = re.compile(r"===\s+(?:Stage=)?(.+?)\s+==\s+(.+)")
71 match_component_finished = re.compile(r"\+\+\s+Finished\s+at")
72
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
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
134 """ Method to override to catch the start stage event. """
135 pass
136
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