sbsv2/raptor/bin/sbs_filter.py
author Jon Chatten
Fri, 12 Nov 2010 14:49:36 +0000
changeset 674 37ee82a83d43
parent 616 24e4ef208cca
permissions -rw-r--r--
sbs version 2.15.3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
591
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
     1
#!/usr/bin/python
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
     2
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
     3
# Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
     4
# All rights reserved.
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
     5
# This component and the accompanying materials are made available
616
24e4ef208cca sbs version 2.14.2
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
     6
# under the terms of the License "Symbian Foundation License v1.0"
591
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
     7
# which accompanies this distribution, and is available
616
24e4ef208cca sbs version 2.14.2
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
     8
# at the URL "http://www.symbianfoundation.org/legal/sfl-v10.html".
591
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
     9
#
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    10
# Initial Contributors:
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    11
# Nokia Corporation - initial contribution.
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    12
#
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    13
# Contributors:
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    14
#
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    15
# Description:
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    16
#
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    17
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    18
import os
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    19
import sys
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    20
import traceback
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    21
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    22
# intercept the -h option
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    23
if "-h" in sys.argv or "--help" in sys.argv:
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    24
	print "usage:", sys.argv[0], "[sbs options]"
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    25
	print "  The log data is read from stdin."
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    26
	print "  Type 'sbs -h' for a list of sbs options."
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    27
	sys.exit(0)
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    28
	
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    29
# get the absolute path to this script
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    30
script = os.path.abspath(sys.argv[0])
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    31
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    32
# add the Raptor python directory to the PYTHONPATH
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    33
sys.path.append(os.path.join(os.path.dirname(script), "..", "python"))
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    34
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    35
# now we should be able to find the raptor modules
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    36
import raptor
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    37
import pluginbox
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    38
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    39
# make sure that HOSTPLATFORM is set
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    40
if not "HOSTPLATFORM" in os.environ:
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    41
	sys.stderr.write("HOSTPLATFORM is not set ... try running gethost.sh\n")
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    42
	sys.exit(1)
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    43
	
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    44
if not "HOSTPLATFORM_DIR" in os.environ:
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    45
	sys.stderr.write("HOSTPLATFORM_DIR is not set ... try running gethost.sh\n")
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    46
	sys.exit(1)
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    47
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    48
# construct a Raptor object from our command-line (less the name of this script)
616
24e4ef208cca sbs version 2.14.2
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
    49
the_raptor = raptor.Raptor.CreateCommandlineAnalysis(sys.argv[1:])
591
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    50
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    51
# from Raptor.OpenLog()
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    52
try:
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    53
	# Find all the raptor plugins and put them into a pluginbox.
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    54
	if not the_raptor.systemPlugins.isAbsolute():
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    55
		the_raptor.systemPlugins = the_raptor.home.Append(the_raptor.systemPlugins)
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    56
		
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    57
	pbox = pluginbox.PluginBox(str(the_raptor.systemPlugins))
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    58
	raptor_params = raptor.BuildStats(the_raptor)
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    59
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    60
	# Open the requested plugins using the pluginbox
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    61
	the_raptor.out.open(raptor_params, the_raptor.filterList, pbox)
674
37ee82a83d43 sbs version 2.15.3
Jon Chatten
parents: 616
diff changeset
    62
37ee82a83d43 sbs version 2.15.3
Jon Chatten
parents: 616
diff changeset
    63
except ValueError, e:
37ee82a83d43 sbs version 2.15.3
Jon Chatten
parents: 616
diff changeset
    64
	sys.stderr.write("error: problem while creating filters: {0}\n".format(str(e)))
37ee82a83d43 sbs version 2.15.3
Jon Chatten
parents: 616
diff changeset
    65
	sys.exit(1)
591
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    66
except Exception, e:
674
37ee82a83d43 sbs version 2.15.3
Jon Chatten
parents: 616
diff changeset
    67
	# Unrecognised exception: print a traceback
37ee82a83d43 sbs version 2.15.3
Jon Chatten
parents: 616
diff changeset
    68
	sys.stderr.write("error: problem while creating filters: {0}\n".format(str(e)))
591
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    69
	traceback.print_exc()
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    70
	sys.exit(1)
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    71
		
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    72
# read stdin a line at a time and pass it to the Raptor object
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    73
try:
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    74
	line = " "
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    75
	while line:
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    76
		line = sys.stdin.readline()
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    77
		the_raptor.out.write(line)
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    78
except Exception,e:
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    79
	sys.stderr.write("error: problem while filtering: %s\n" % str(e))
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    80
	traceback.print_exc()
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    81
	sys.exit(1)
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    82
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    83
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    84
# Print the summary (this can't return errors)
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    85
the_raptor.out.summary()
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    86
	
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    87
if not the_raptor.out.close():
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    88
	the_raptor.errorCode = 2
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    89
	
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    90
# return the error code
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    91
sys.exit(the_raptor.errorCode)
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    92