concatlogs.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #!/usr/bin/env python
  2. """ Combines multiple uniform HTML documents with tables into a single one.
  3. HTML header from the first document will be used in the output document. Largest
  4. `<tbody>...</tbody>` part from each document will be joined together.
  5. """
  6. from optparse import OptionParser
  7. import glob, sys, os, re
  8. if __name__ == "__main__":
  9. parser = OptionParser()
  10. parser.add_option("-o", "--output", dest="output", help="output file name", metavar="FILENAME", default=None)
  11. (options, args) = parser.parse_args()
  12. if not options.output:
  13. sys.stderr.write("Error: output file name is not provided")
  14. exit(-1)
  15. files = []
  16. for arg in args:
  17. if ("*" in arg) or ("?" in arg):
  18. files.extend([os.path.abspath(f) for f in glob.glob(arg)])
  19. else:
  20. files.append(os.path.abspath(arg))
  21. html = None
  22. for f in sorted(files):
  23. try:
  24. fobj = open(f)
  25. if not fobj:
  26. continue
  27. text = fobj.read()
  28. if not html:
  29. html = text
  30. continue
  31. idx1 = text.find("<tbody>") + len("<tbody>")
  32. idx2 = html.rfind("</tbody>")
  33. html = html[:idx2] + re.sub(r"[ \t\n\r]+", " ", text[idx1:])
  34. except:
  35. pass
  36. if html:
  37. idx1 = text.find("<title>") + len("<title>")
  38. idx2 = html.find("</title>")
  39. html = html[:idx1] + "OpenCV performance testing report" + html[idx2:]
  40. open(options.output, "w").write(html)
  41. else:
  42. sys.stderr.write("Error: no input data")
  43. exit(-1)