create_diffs_tarball.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #!/usr/bin/env python
  2. # Copyright 2016 The Chromium Authors. All rights reserved.
  3. # Use of this source code is governed by a BSD-style license that can be
  4. # found in the LICENSE file.
  5. """Create tarball of differences."""
  6. import argparse
  7. import json
  8. import os
  9. import shutil
  10. import sys
  11. import tarfile
  12. import tempfile
  13. def CreateArchive(first, second, input_files, output_file):
  14. """Create archive of input files to output_dir.
  15. Args:
  16. first: the first build directory.
  17. second: the second build directory.
  18. input_files: list of input files to be archived.
  19. output_file: an output file.
  20. """
  21. with tarfile.open(name=output_file, mode='w:gz') as tf:
  22. for f in input_files:
  23. tf.add(os.path.join(first, f))
  24. tf.add(os.path.join(second, f))
  25. def main():
  26. parser = argparse.ArgumentParser()
  27. parser.add_argument('-f', '--first-build-dir',
  28. help='The first build directory')
  29. parser.add_argument('-s', '--second-build-dir',
  30. help='The second build directory')
  31. parser.add_argument('--json-input',
  32. help='JSON file to specify list of files to archive.')
  33. parser.add_argument('--output', help='output filename.')
  34. args = parser.parse_args()
  35. if not args.first_build_dir:
  36. parser.error('--first-build-dir is required')
  37. if not args.second_build_dir:
  38. parser.error('--second-build-dir is required')
  39. if not args.json_input:
  40. parser.error('--json-input is required')
  41. if not args.output:
  42. parser.error('--output is required')
  43. with open(args.json_input) as f:
  44. input_files = json.load(f)
  45. CreateArchive(args.first_build_dir, args.second_build_dir, input_files,
  46. args.output)
  47. if __name__ == '__main__':
  48. sys.exit(main())