scrape_gtest_log.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. # Copyright (c) 2014 The WebM project authors. All Rights Reserved.
  2. #
  3. # Use of this source code is governed by a BSD-style license
  4. # that can be found in the LICENSE file in the root of the source
  5. # tree. An additional intellectual property rights grant can be found
  6. # in the file PATENTS. All contributing project authors may
  7. # be found in the AUTHORS file in the root of the source tree.
  8. """Standalone script which parses a gtest log for json.
  9. Json is returned returns as an array. This script is used by the libvpx
  10. waterfall to gather json results mixed in with gtest logs. This is
  11. dubious software engineering.
  12. """
  13. import getopt
  14. import json
  15. import os
  16. import re
  17. import sys
  18. def main():
  19. if len(sys.argv) != 3:
  20. print "Expects a file to write json to!"
  21. exit(1)
  22. try:
  23. opts, _ = \
  24. getopt.getopt(sys.argv[1:], \
  25. 'o:', ['output-json='])
  26. except getopt.GetOptError:
  27. print 'scrape_gtest_log.py -o <output_json>'
  28. sys.exit(2)
  29. output_json = ''
  30. for opt, arg in opts:
  31. if opt in ('-o', '--output-json'):
  32. output_json = os.path.join(arg)
  33. blob = sys.stdin.read()
  34. json_string = '[' + ','.join('{' + x + '}' for x in
  35. re.findall(r'{([^}]*.?)}', blob)) + ']'
  36. print blob
  37. output = json.dumps(json.loads(json_string), indent=4, sort_keys=True)
  38. print output
  39. path = os.path.dirname(output_json)
  40. if path and not os.path.exists(path):
  41. os.makedirs(path)
  42. outfile = open(output_json, 'w')
  43. outfile.write(output)
  44. if __name__ == '__main__':
  45. sys.exit(main())