sbsv2/raptor/bin/sbs_filter.py
author Iain Williamson <iain.williamson@nokia.com>
Thu, 03 Jun 2010 16:34:48 +0100
changeset 580 6209aeff0f73
parent 453 aa590b420880
child 598 0a541d1f13c3
permissions -rwxr-xr-x
Fixing sbs_filter issue.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
     1
#!/usr/bin/python
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
     2
453
aa590b420880 apply review comments
Richard Taylor <richard.i.taylor@nokia.com>
parents: 451
diff changeset
     3
# Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
5
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
     4
# All rights reserved.
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
     5
# This component and the accompanying materials are made available
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
     6
# under the terms of the License "Symbian Foundation License v1.0"
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
     7
# which accompanies this distribution, and is available
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
     8
# at the URL "http://www.symbianfoundation.org/legal/sfl-v10.html".
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
     9
#
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    10
# Initial Contributors:
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    11
# Nokia Corporation - initial contribution.
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    12
#
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    13
# Contributors:
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    14
#
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    15
# Description:
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    16
#
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    17
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    18
import os
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    19
import sys
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    20
import traceback
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    21
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    22
# intercept the -h option
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    23
if "-h" in sys.argv or "--help" in sys.argv:
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    24
	print "usage:", sys.argv[0], "[sbs options]"
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    25
	print "  The log data is read from stdin."
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    26
	print "  Type 'sbs -h' for a list of sbs options."
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    27
	sys.exit(0)
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    28
	
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    29
# get the absolute path to this script
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    30
script = os.path.abspath(sys.argv[0])
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    31
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    32
# add the Raptor python directory to the PYTHONPATH
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    33
sys.path.append(os.path.join(os.path.dirname(script), "..", "python"))
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    34
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    35
# now we should be able to find the raptor modules
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    36
import raptor
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    37
import pluginbox
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    38
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    39
# make sure that HOSTPLATFORM is set
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    40
if not "HOSTPLATFORM" in os.environ:
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    41
	sys.stderr.write("HOSTPLATFORM is not set ... try running gethost.sh\n")
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    42
	sys.exit(1)
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    43
	
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    44
if not "HOSTPLATFORM_DIR" in os.environ:
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    45
	sys.stderr.write("HOSTPLATFORM_DIR is not set ... try running gethost.sh\n")
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    46
	sys.exit(1)
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    47
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    48
# construct a Raptor object from our command-line (less the name of this script)
580
6209aeff0f73 Fixing sbs_filter issue.
Iain Williamson <iain.williamson@nokia.com>
parents: 453
diff changeset
    49
the_raptor = raptor.Raptor.CreateCommandlineAnalysis(sys.argv[1:])
5
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    50
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    51
# from Raptor.OpenLog()
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    52
try:
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    53
	# Find all the raptor plugins and put them into a pluginbox.
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    54
	if not the_raptor.systemPlugins.isAbsolute():
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    55
		the_raptor.systemPlugins = the_raptor.home.Append(the_raptor.systemPlugins)
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    56
		
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    57
	pbox = pluginbox.PluginBox(str(the_raptor.systemPlugins))
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    58
	raptor_params = raptor.BuildStats(the_raptor)
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    59
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    60
	# Open the requested plugins using the pluginbox
451
153129bf777e pass optional parameters to log filters from the command line
Richard Taylor <richard.i.taylor@nokia.com>
parents: 202
diff changeset
    61
	the_raptor.out.open(raptor_params, the_raptor.filterList, pbox)
5
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    62
	
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    63
except Exception, e:
124
e898967975af sbs_filter: Fix so that return code is 0 on success (was always 1)
timothy.murphy@nokia.com
parents: 115
diff changeset
    64
	sys.stderr.write("error: problem while creating filters %s\n" % str(e))
115
5869e06bf2ac Cause whatcomp output to use the incoming epocroot value. i.e. if epocroot is relative then so is the what output.
timothy.murphy@nokia.com
parents: 5
diff changeset
    65
	traceback.print_exc()
5
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    66
	sys.exit(1)
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    67
		
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    68
# read stdin a line at a time and pass it to the Raptor object
124
e898967975af sbs_filter: Fix so that return code is 0 on success (was always 1)
timothy.murphy@nokia.com
parents: 115
diff changeset
    69
try:
e898967975af sbs_filter: Fix so that return code is 0 on success (was always 1)
timothy.murphy@nokia.com
parents: 115
diff changeset
    70
	line = " "
e898967975af sbs_filter: Fix so that return code is 0 on success (was always 1)
timothy.murphy@nokia.com
parents: 115
diff changeset
    71
	while line:
e898967975af sbs_filter: Fix so that return code is 0 on success (was always 1)
timothy.murphy@nokia.com
parents: 115
diff changeset
    72
		line = sys.stdin.readline()
e898967975af sbs_filter: Fix so that return code is 0 on success (was always 1)
timothy.murphy@nokia.com
parents: 115
diff changeset
    73
		the_raptor.out.write(line)
202
5ec640568a23 FilterCheckComp - checking file existence by component
timothy.murphy@nokia.com
parents: 132
diff changeset
    74
except Exception,e:
124
e898967975af sbs_filter: Fix so that return code is 0 on success (was always 1)
timothy.murphy@nokia.com
parents: 115
diff changeset
    75
	sys.stderr.write("error: problem while filtering: %s\n" % str(e))
e898967975af sbs_filter: Fix so that return code is 0 on success (was always 1)
timothy.murphy@nokia.com
parents: 115
diff changeset
    76
	traceback.print_exc()
e898967975af sbs_filter: Fix so that return code is 0 on success (was always 1)
timothy.murphy@nokia.com
parents: 115
diff changeset
    77
	sys.exit(1)
5
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    78
124
e898967975af sbs_filter: Fix so that return code is 0 on success (was always 1)
timothy.murphy@nokia.com
parents: 115
diff changeset
    79
e898967975af sbs_filter: Fix so that return code is 0 on success (was always 1)
timothy.murphy@nokia.com
parents: 115
diff changeset
    80
# Print the summary (this can't return errors)
e898967975af sbs_filter: Fix so that return code is 0 on success (was always 1)
timothy.murphy@nokia.com
parents: 115
diff changeset
    81
the_raptor.out.summary()
5
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    82
	
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    83
if not the_raptor.out.close():
124
e898967975af sbs_filter: Fix so that return code is 0 on success (was always 1)
timothy.murphy@nokia.com
parents: 115
diff changeset
    84
	the_raptor.errorCode = 2
5
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    85
	
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    86
# return the error code
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    87
sys.exit(the_raptor.errorCode)
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    88