3
|
1 |
#
|
|
2 |
# Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
# All rights reserved.
|
|
4 |
# This component and the accompanying materials are made available
|
|
5 |
# under the terms of the License "Eclipse Public License v1.0"
|
|
6 |
# which accompanies this distribution, and is available
|
|
7 |
# at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
#
|
|
9 |
# Initial Contributors:
|
|
10 |
# Nokia Corporation - initial contribution.
|
|
11 |
#
|
|
12 |
# Contributors:
|
|
13 |
#
|
|
14 |
# Description:
|
|
15 |
# Filter class for filtering XML logs and generate reports
|
|
16 |
# Will ultimately do everything that scanlog does
|
|
17 |
#
|
|
18 |
|
|
19 |
import os
|
|
20 |
import sys
|
|
21 |
import raptor
|
|
22 |
import filter_interface
|
|
23 |
|
|
24 |
class FilterLogfile(filter_interface.Filter):
|
|
25 |
|
|
26 |
def open(self, raptor_instance):
|
|
27 |
"""Open a log file for the various I/O methods to write to."""
|
|
28 |
|
|
29 |
self.raptor = raptor_instance
|
|
30 |
self.logFileName = self.raptor.logFileName
|
|
31 |
# insert the time into the log file name
|
|
32 |
if self.logFileName:
|
|
33 |
self.logFileName.path = self.logFileName.path.replace("%TIME",
|
|
34 |
self.raptor.timestring)
|
|
35 |
|
|
36 |
try:
|
|
37 |
dirname = str(self.raptor.logFileName.Dir())
|
|
38 |
if dirname and not os.path.isdir(dirname):
|
|
39 |
os.makedirs(dirname)
|
|
40 |
except os.error, e:
|
|
41 |
if e.errno != os.errno.EEXIST:
|
|
42 |
sys.stderr.write("%s : error: cannot create directory %s\n" % \
|
|
43 |
(str(raptor.name), dirname))
|
|
44 |
return False
|
|
45 |
try:
|
|
46 |
self.out = open(str(self.logFileName), "w")
|
|
47 |
except:
|
|
48 |
self.out = None
|
|
49 |
sys.stderr.write("%s : error: cannot write log %s\n" %\
|
|
50 |
(str(raptor.name), self.logFileName.GetShellPath()))
|
|
51 |
return False
|
|
52 |
else:
|
|
53 |
self.out = sys.stdout
|
|
54 |
|
|
55 |
return True
|
|
56 |
|
|
57 |
def write(self, text):
|
|
58 |
"""Write text into the log file"""
|
|
59 |
|
|
60 |
self.out.write(text)
|
|
61 |
return True
|
|
62 |
|
|
63 |
def summary(self):
|
|
64 |
"""Write Summary"""
|
|
65 |
if self.logFileName and not self.raptor.quiet:
|
|
66 |
sys.stdout.write("sbs: build log in %s\n" % str(self.logFileName))
|
|
67 |
return False
|
|
68 |
|
|
69 |
def close(self):
|
|
70 |
"""Close the log file"""
|
|
71 |
|
|
72 |
try:
|
|
73 |
self.out.close()
|
|
74 |
return True
|
|
75 |
except:
|
|
76 |
self.out = None
|
|
77 |
return False
|