michael@0: # This Source Code Form is subject to the terms of the Mozilla Public michael@0: # License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: # file, You can obtain one at http://mozilla.org/MPL/2.0/. michael@0: michael@0: from __future__ import print_function, unicode_literals michael@0: michael@0: import collections michael@0: import json michael@0: import os michael@0: import sys michael@0: michael@0: import writeBuildFiles michael@0: michael@0: def extractLines(fp): michael@0: lines = [] michael@0: watch = False michael@0: for line in fp: michael@0: line = line.decode('utf-8') michael@0: if line == '@@@ @@@ Failures\n': michael@0: watch = True michael@0: elif watch: michael@0: watch = False michael@0: idx = line.index('@@@') michael@0: lines.append((line[:idx], line[idx + 3:])) michael@0: return lines michael@0: michael@0: def ensuredir(path): michael@0: dir = path[:path.rfind('/')] michael@0: if not os.path.exists(dir): michael@0: os.makedirs(dir) michael@0: michael@0: def dumpFailures(lines): michael@0: files = [] michael@0: for url, objstr in lines: michael@0: if objstr == '{}\n': michael@0: continue michael@0: michael@0: # Avoid overly large diffs. michael@0: if 'editing/' in url: michael@0: sep = ':' michael@0: else: michael@0: sep = ': ' michael@0: michael@0: jsonpath = 'failures/' + url + '.json' michael@0: files.append(jsonpath) michael@0: ensuredir(jsonpath) michael@0: obj = json.loads(objstr, object_pairs_hook=collections.OrderedDict) michael@0: formattedobjstr = json.dumps(obj, indent=2, separators=(',', sep)) + '\n' michael@0: formattedobj = formattedobjstr.encode('utf-8') michael@0: fp = open(jsonpath, 'wb') michael@0: fp.write(formattedobj) michael@0: fp.close() michael@0: return files michael@0: michael@0: def writeFiles(files): michael@0: pathmap = {} michael@0: for path in files: michael@0: dirp, leaf = path.rsplit('/', 1) michael@0: pathmap.setdefault(dirp, []).append(leaf) michael@0: michael@0: for k, v in pathmap.items(): michael@0: with open(k + '/mochitest.ini', 'w') as fh: michael@0: result = writeBuildFiles.substManifest('parseFailures.py', v, []) michael@0: fh.write(result) michael@0: michael@0: michael@0: def main(logPath): michael@0: fp = open(logPath, 'rb') michael@0: lines = extractLines(fp) michael@0: fp.close() michael@0: michael@0: files = dumpFailures(lines) michael@0: writeFiles(files) michael@0: michael@0: if __name__ == '__main__': michael@0: if len(sys.argv) < 2: michael@0: print("Please pass the path to the logfile from which failures should be extracted.") michael@0: main(sys.argv[1]) michael@0: