sbsv2/raptor/python/filter_interface.py
author timothy.murphy@nokia.com
Fri, 12 Feb 2010 14:57:02 +0200
branchfix
changeset 204 a19456c07783
parent 9 b211d87c390a
permissions -rw-r--r--
fix: failure of make engine test when a make engine alias contains a modifier. There can be more than one variant per alias via "." e.g. make.extrastuff where make and extrastuff are variants.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
     1
#
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
     2
# Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
     3
# All rights reserved.
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
     4
# This component and the accompanying materials are made available
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
     5
# under the terms of the License "Eclipse Public License v1.0"
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
     6
# which accompanies this distribution, and is available
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
     7
# at the URL "http://www.eclipse.org/legal/epl-v10.html".
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
     8
#
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
     9
# Initial Contributors:
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    10
# Nokia Corporation - initial contribution.
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    11
#
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    12
# Contributors:
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    13
#
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    14
# Description: 
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    15
# Base Class for defining filter classes
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    16
# All filter classes that get defined should derive from this base class
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    17
#
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    18
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    19
class Filter(object):
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    20
	
5
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents: 3
diff changeset
    21
	def open(self, params):
3
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    22
		return False
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    23
	
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    24
	def write(self, text):
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    25
		return False
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    26
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    27
	def summary(self):
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    28
		return False
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    29
	
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    30
	def close(self):
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    31
		return False
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    32
	
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    33
	def formatError(self, message):
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    34
		return "sbs: error: " + message + "\n"
5
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents: 3
diff changeset
    35
		
9
b211d87c390a Update to 2.11.0 from perforce
timothy.murphy@nokia.com
parents: 5
diff changeset
    36
	def formatWarning(self, message):
b211d87c390a Update to 2.11.0 from perforce
timothy.murphy@nokia.com
parents: 5
diff changeset
    37
		return "sbs: warning: " + message + "\n"	
5
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents: 3
diff changeset
    38
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents: 3
diff changeset
    39
import sys
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents: 3
diff changeset
    40
import xml.sax
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents: 3
diff changeset
    41
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents: 3
diff changeset
    42
class FilterSAX(Filter, xml.sax.handler.ContentHandler, xml.sax.handler.ErrorHandler):
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents: 3
diff changeset
    43
	"base class for filters using a SAX parser"
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents: 3
diff changeset
    44
	
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents: 3
diff changeset
    45
	# define these methods in your subclass
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents: 3
diff changeset
    46
	
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents: 3
diff changeset
    47
	def startDocument(self):
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents: 3
diff changeset
    48
		"called once before any elements are seen"
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents: 3
diff changeset
    49
		pass
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents: 3
diff changeset
    50
		
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents: 3
diff changeset
    51
	def startElement(self, name, attributes):
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents: 3
diff changeset
    52
		"called on the opening of any element"
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents: 3
diff changeset
    53
		pass
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents: 3
diff changeset
    54
	
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents: 3
diff changeset
    55
	def characters(self, char):
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents: 3
diff changeset
    56
		"called one or more times with body text from an element"
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents: 3
diff changeset
    57
		pass
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents: 3
diff changeset
    58
		
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents: 3
diff changeset
    59
	def endElement(self, name):
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents: 3
diff changeset
    60
		"called on the closing of any element"
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents: 3
diff changeset
    61
		pass
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents: 3
diff changeset
    62
	
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents: 3
diff changeset
    63
	def endDocument(self):
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents: 3
diff changeset
    64
		"called once when all elements are closed"
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents: 3
diff changeset
    65
		pass
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents: 3
diff changeset
    66
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents: 3
diff changeset
    67
	def error(self, exception):
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents: 3
diff changeset
    68
		"the parse found an error which is (possibly) recoverable"
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents: 3
diff changeset
    69
		pass
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents: 3
diff changeset
    70
		
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents: 3
diff changeset
    71
	def fatalError(self, exception):
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents: 3
diff changeset
    72
		"the parser thinks an error occurred which should stop everything"
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents: 3
diff changeset
    73
		pass
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents: 3
diff changeset
    74
		
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents: 3
diff changeset
    75
	def warning(self, exception):
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents: 3
diff changeset
    76
		"the parser found something to complain about that might not matter"
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents: 3
diff changeset
    77
		pass
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents: 3
diff changeset
    78
		
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents: 3
diff changeset
    79
	# these methods are from the Filter base class
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents: 3
diff changeset
    80
	
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents: 3
diff changeset
    81
	def open(self, params):
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents: 3
diff changeset
    82
		"initialise"
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents: 3
diff changeset
    83
		
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents: 3
diff changeset
    84
		self.params = params
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents: 3
diff changeset
    85
		self.ok = True
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents: 3
diff changeset
    86
		try:
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents: 3
diff changeset
    87
			self.parser = xml.sax.make_parser(['xml.sax.expatreader'])
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents: 3
diff changeset
    88
			self.parser.setContentHandler(self)
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents: 3
diff changeset
    89
			self.parser.setErrorHandler(self)
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents: 3
diff changeset
    90
			
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents: 3
diff changeset
    91
		except Exception, ex:
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents: 3
diff changeset
    92
			sys.stderr.write(self.formatError(str(ex)))
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents: 3
diff changeset
    93
			self.ok = False
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents: 3
diff changeset
    94
		
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents: 3
diff changeset
    95
		return self.ok
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents: 3
diff changeset
    96
	
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents: 3
diff changeset
    97
		
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents: 3
diff changeset
    98
	def write(self, text):
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents: 3
diff changeset
    99
		"process some log text"
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents: 3
diff changeset
   100
		try:
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents: 3
diff changeset
   101
			self.parser.feed(text)
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents: 3
diff changeset
   102
		except Exception, ex:
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents: 3
diff changeset
   103
			sys.stderr.write(self.formatError(str(ex)))
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents: 3
diff changeset
   104
			self.ok = False
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents: 3
diff changeset
   105
				
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents: 3
diff changeset
   106
		return self.ok
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents: 3
diff changeset
   107
	
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents: 3
diff changeset
   108
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents: 3
diff changeset
   109
	def close(self):
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents: 3
diff changeset
   110
		"finish off"
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents: 3
diff changeset
   111
		try:
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents: 3
diff changeset
   112
			self.parser.close()
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents: 3
diff changeset
   113
		except Exception, ex:
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents: 3
diff changeset
   114
			sys.stderr.write(self.formatError(str(ex)))
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents: 3
diff changeset
   115
			self.ok = False
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents: 3
diff changeset
   116
			
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents: 3
diff changeset
   117
		return self.ok
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents: 3
diff changeset
   118
	
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents: 3
diff changeset
   119
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents: 3
diff changeset
   120
# the end