merge_coverage_data.py 1.2 KB

1234567891011121314151617181920212223242526272829303132
  1. import sys
  2. import tarfile
  3. import copy
  4. import os
  5. import uuid
  6. def main(args):
  7. output_file, args = args[0], args[1:]
  8. # heretic@: Splits files on which could be merged( files ) and which should not be merged( expendables )
  9. # expendables will be in output_file in form {name}{ordinal number of archive in args[]}.{extension}
  10. try:
  11. split_i = args.index('-no-merge')
  12. except ValueError:
  13. split_i = len(args)
  14. files, expendables = args[:split_i], args[split_i + 1:]
  15. with tarfile.open(output_file, 'w') as outf:
  16. for x in files:
  17. with tarfile.open(x) as tf:
  18. for tarinfo in tf:
  19. new_tarinfo = copy.deepcopy(tarinfo)
  20. if new_tarinfo.name in expendables:
  21. dirname, basename = os.path.split(new_tarinfo.name)
  22. basename_parts = basename.split('.', 1)
  23. new_basename = '.'.join([basename_parts[0] + str(uuid.uuid4())] + basename_parts[1:])
  24. new_tarinfo.name = os.path.join(dirname, new_basename)
  25. outf.addfile(new_tarinfo, tf.extractfile(tarinfo))
  26. if __name__ == '__main__':
  27. main(sys.argv[1:])