dom/imptests/parseFailures.py

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 # This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 # License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
michael@0 4
michael@0 5 from __future__ import print_function, unicode_literals
michael@0 6
michael@0 7 import collections
michael@0 8 import json
michael@0 9 import os
michael@0 10 import sys
michael@0 11
michael@0 12 import writeBuildFiles
michael@0 13
michael@0 14 def extractLines(fp):
michael@0 15 lines = []
michael@0 16 watch = False
michael@0 17 for line in fp:
michael@0 18 line = line.decode('utf-8')
michael@0 19 if line == '@@@ @@@ Failures\n':
michael@0 20 watch = True
michael@0 21 elif watch:
michael@0 22 watch = False
michael@0 23 idx = line.index('@@@')
michael@0 24 lines.append((line[:idx], line[idx + 3:]))
michael@0 25 return lines
michael@0 26
michael@0 27 def ensuredir(path):
michael@0 28 dir = path[:path.rfind('/')]
michael@0 29 if not os.path.exists(dir):
michael@0 30 os.makedirs(dir)
michael@0 31
michael@0 32 def dumpFailures(lines):
michael@0 33 files = []
michael@0 34 for url, objstr in lines:
michael@0 35 if objstr == '{}\n':
michael@0 36 continue
michael@0 37
michael@0 38 # Avoid overly large diffs.
michael@0 39 if 'editing/' in url:
michael@0 40 sep = ':'
michael@0 41 else:
michael@0 42 sep = ': '
michael@0 43
michael@0 44 jsonpath = 'failures/' + url + '.json'
michael@0 45 files.append(jsonpath)
michael@0 46 ensuredir(jsonpath)
michael@0 47 obj = json.loads(objstr, object_pairs_hook=collections.OrderedDict)
michael@0 48 formattedobjstr = json.dumps(obj, indent=2, separators=(',', sep)) + '\n'
michael@0 49 formattedobj = formattedobjstr.encode('utf-8')
michael@0 50 fp = open(jsonpath, 'wb')
michael@0 51 fp.write(formattedobj)
michael@0 52 fp.close()
michael@0 53 return files
michael@0 54
michael@0 55 def writeFiles(files):
michael@0 56 pathmap = {}
michael@0 57 for path in files:
michael@0 58 dirp, leaf = path.rsplit('/', 1)
michael@0 59 pathmap.setdefault(dirp, []).append(leaf)
michael@0 60
michael@0 61 for k, v in pathmap.items():
michael@0 62 with open(k + '/mochitest.ini', 'w') as fh:
michael@0 63 result = writeBuildFiles.substManifest('parseFailures.py', v, [])
michael@0 64 fh.write(result)
michael@0 65
michael@0 66
michael@0 67 def main(logPath):
michael@0 68 fp = open(logPath, 'rb')
michael@0 69 lines = extractLines(fp)
michael@0 70 fp.close()
michael@0 71
michael@0 72 files = dumpFailures(lines)
michael@0 73 writeFiles(files)
michael@0 74
michael@0 75 if __name__ == '__main__':
michael@0 76 if len(sys.argv) < 2:
michael@0 77 print("Please pass the path to the logfile from which failures should be extracted.")
michael@0 78 main(sys.argv[1])
michael@0 79

mercurial