1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/imptests/parseFailures.py Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,79 @@ 1.4 +# This Source Code Form is subject to the terms of the Mozilla Public 1.5 +# License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 +# file, You can obtain one at http://mozilla.org/MPL/2.0/. 1.7 + 1.8 +from __future__ import print_function, unicode_literals 1.9 + 1.10 +import collections 1.11 +import json 1.12 +import os 1.13 +import sys 1.14 + 1.15 +import writeBuildFiles 1.16 + 1.17 +def extractLines(fp): 1.18 + lines = [] 1.19 + watch = False 1.20 + for line in fp: 1.21 + line = line.decode('utf-8') 1.22 + if line == '@@@ @@@ Failures\n': 1.23 + watch = True 1.24 + elif watch: 1.25 + watch = False 1.26 + idx = line.index('@@@') 1.27 + lines.append((line[:idx], line[idx + 3:])) 1.28 + return lines 1.29 + 1.30 +def ensuredir(path): 1.31 + dir = path[:path.rfind('/')] 1.32 + if not os.path.exists(dir): 1.33 + os.makedirs(dir) 1.34 + 1.35 +def dumpFailures(lines): 1.36 + files = [] 1.37 + for url, objstr in lines: 1.38 + if objstr == '{}\n': 1.39 + continue 1.40 + 1.41 + # Avoid overly large diffs. 1.42 + if 'editing/' in url: 1.43 + sep = ':' 1.44 + else: 1.45 + sep = ': ' 1.46 + 1.47 + jsonpath = 'failures/' + url + '.json' 1.48 + files.append(jsonpath) 1.49 + ensuredir(jsonpath) 1.50 + obj = json.loads(objstr, object_pairs_hook=collections.OrderedDict) 1.51 + formattedobjstr = json.dumps(obj, indent=2, separators=(',', sep)) + '\n' 1.52 + formattedobj = formattedobjstr.encode('utf-8') 1.53 + fp = open(jsonpath, 'wb') 1.54 + fp.write(formattedobj) 1.55 + fp.close() 1.56 + return files 1.57 + 1.58 +def writeFiles(files): 1.59 + pathmap = {} 1.60 + for path in files: 1.61 + dirp, leaf = path.rsplit('/', 1) 1.62 + pathmap.setdefault(dirp, []).append(leaf) 1.63 + 1.64 + for k, v in pathmap.items(): 1.65 + with open(k + '/mochitest.ini', 'w') as fh: 1.66 + result = writeBuildFiles.substManifest('parseFailures.py', v, []) 1.67 + fh.write(result) 1.68 + 1.69 + 1.70 +def main(logPath): 1.71 + fp = open(logPath, 'rb') 1.72 + lines = extractLines(fp) 1.73 + fp.close() 1.74 + 1.75 + files = dumpFailures(lines) 1.76 + writeFiles(files) 1.77 + 1.78 +if __name__ == '__main__': 1.79 + if len(sys.argv) < 2: 1.80 + print("Please pass the path to the logfile from which failures should be extracted.") 1.81 + main(sys.argv[1]) 1.82 +