extract_jacoco_report.py 1002 B

1234567891011121314151617181920212223242526272829
  1. import argparse
  2. import os
  3. import re
  4. import tarfile
  5. if __name__ == '__main__':
  6. parser = argparse.ArgumentParser()
  7. parser.add_argument('--archive', action='store')
  8. parser.add_argument('--source-re', action='store')
  9. parser.add_argument('--destination', action='store')
  10. args = parser.parse_args()
  11. with tarfile.open(args.archive) as tf:
  12. open(args.destination, 'wb').close()
  13. extract_list = []
  14. matcher = re.compile(args.source_re)
  15. temp_dir = os.path.join(os.path.dirname(args.destination), 'temp_profiles')
  16. if not os.path.exists(temp_dir):
  17. os.makedirs(temp_dir)
  18. for f in [i for i in tf if matcher.match(i.name)]:
  19. tf.extract(f, path=temp_dir)
  20. for directory, _, srcs in os.walk(temp_dir):
  21. for f in srcs:
  22. with open(args.destination, 'ab') as dst:
  23. with open(os.path.join(temp_dir, directory, f), 'rb') as src:
  24. dst.write(src.read())