comparison mx/outputparser.py @ 4225:339cf8d4904d

Made mx.run work properly when stderr is redirected to stdout. Made outputparser redirect stderr to stdout. Added copyright headers to outputparser.py and sanitycheck.py. Reverted class path construction in mx.build() to use includeSelf=True to fix regression when running 'mx build -c'.
author Doug Simon <doug.simon@oracle.com>
date Thu, 05 Jan 2012 11:31:46 +0100
parents 47f7d91d34cf
children 063ea022532c
comparison
equal deleted inserted replaced
4224:26336f60ec7a 4225:339cf8d4904d
1 # ----------------------------------------------------------------------------------------------------
2 #
3 # Copyright (c) 2007, 2012, Oracle and/or its affiliates. All rights reserved.
4 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 #
6 # This code is free software; you can redistribute it and/or modify it
7 # under the terms of the GNU General Public License version 2 only, as
8 # published by the Free Software Foundation.
9 #
10 # This code is distributed in the hope that it will be useful, but WITHOUT
11 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 # version 2 for more details (a copy is included in the LICENSE file that
14 # accompanied this code).
15 #
16 # You should have received a copy of the GNU General Public License version
17 # 2 along with this work; if not, write to the Free Software Foundation,
18 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19 #
20 # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21 # or visit www.oracle.com if you need additional information or have any
22 # questions.
23 #
24 # ----------------------------------------------------------------------------------------------------
25
1 import mx 26 import mx
2 import commands 27 import commands
28 import subprocess
3 29
4 class OutputParser: 30 class OutputParser:
5 31
6 def __init__(self, nonZeroIsFatal=True): 32 def __init__(self, nonZeroIsFatal=True):
7 self.matchers = [] 33 self.matchers = []
25 if anyMatch : 51 if anyMatch :
26 mx.log('>' + line.rstrip()) 52 mx.log('>' + line.rstrip())
27 else : 53 else :
28 mx.log( line.rstrip()) 54 mx.log( line.rstrip())
29 55
30 retcode = commands.vm(cmd, vm, nonZeroIsFatal=self.nonZeroIsFatal, out=parseLine, err=parseLine, cwd=cwd, vmbuild=vmbuild) 56 retcode = commands.vm(cmd, vm, nonZeroIsFatal=self.nonZeroIsFatal, out=parseLine, err=subprocess.STDOUT, cwd=cwd, vmbuild=vmbuild)
31 return {'parsed' : ret, 'retcode' : retcode} 57 return {'parsed' : ret, 'retcode' : retcode}
32 58
33 class Matcher: 59 class Matcher:
34 60
35 def __init__(self, regex, valuesToParse, startNewLine=False): 61 def __init__(self, regex, valuesToParse, startNewLine=False):
48 return ret 74 return ret
49 75
50 def parsestr(self, match, key): 76 def parsestr(self, match, key):
51 if isinstance(key, tuple): 77 if isinstance(key, tuple):
52 if len(key) != 2: 78 if len(key) != 2:
53 raise Exception('Tuple arguments must have a lenght of 2') 79 raise Exception('Tuple arguments must have a length of 2')
54 tup1, tup2 = key 80 tup1, tup2 = key
55 # check if key is a function 81 # check if key is a function
56 if hasattr(tup1, '__call__'): 82 if hasattr(tup1, '__call__'):
57 return tup1(self.parsestr(match, tup2)) 83 return tup1(self.parsestr(match, tup2))
58 elif hasattr(tup2, '__call__'): 84 elif hasattr(tup2, '__call__'):