concatlogs.py 1.3 KB

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