| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 # Copyright (c) 2009 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 """ | 6 """ |
| 7 This tool creates a tarball with all the sources, but without .svn directories. | 7 This tool creates a tarball with all the sources, but without .svn directories. |
| 8 | 8 |
| 9 It can also remove files which are not strictly required for build, so that | 9 It can also remove files which are not strictly required for build, so that |
| 10 the resulting tarball can be reasonably small (last time it was ~110 MB). | 10 the resulting tarball can be reasonably small (last time it was ~110 MB). |
| 11 | 11 |
| 12 Example usage: | 12 Example usage: |
| 13 | 13 |
| 14 export_tarball.py /foo/bar | 14 export_tarball.py /foo/bar |
| 15 | 15 |
| 16 The above will create file /foo/bar.tar.bz2. | 16 The above will create file /foo/bar.tar.bz2. |
| 17 """ | 17 """ |
| 18 | 18 |
| 19 from __future__ import with_statement | |
| 20 | |
| 21 import contextlib | |
| 22 import optparse | 19 import optparse |
| 23 import os | 20 import os |
| 24 import sys | 21 import sys |
| 25 import tarfile | 22 import tarfile |
| 26 | 23 |
| 27 NONESSENTIAL_DIRS = ( | 24 NONESSENTIAL_DIRS = ( |
| 28 'chrome/test/data', | 25 'chrome/test/data', |
| 29 'chrome/tools/test/reference_build', | 26 'chrome/tools/test/reference_build', |
| 30 'gears/binaries', | 27 'gears/binaries', |
| 31 'net/data/cache_tests', | 28 'net/data/cache_tests', |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 return True | 64 return True |
| 68 | 65 |
| 69 if not options.remove_nonessential_files: | 66 if not options.remove_nonessential_files: |
| 70 return False | 67 return False |
| 71 for nonessential_dir in NONESSENTIAL_DIRS: | 68 for nonessential_dir in NONESSENTIAL_DIRS: |
| 72 if path.startswith(os.path.join(GetSourceDirectory(), nonessential_dir)): | 69 if path.startswith(os.path.join(GetSourceDirectory(), nonessential_dir)): |
| 73 return True | 70 return True |
| 74 | 71 |
| 75 return False | 72 return False |
| 76 | 73 |
| 77 with contextlib.closing(tarfile.open(output_fullname, 'w:bz2')) as archive: | 74 archive = tarfile.open(output_fullname, 'w:bz2') |
| 75 try: |
| 78 archive.add(GetSourceDirectory(), arcname=output_basename, | 76 archive.add(GetSourceDirectory(), arcname=output_basename, |
| 79 exclude=ShouldExcludePath) | 77 exclude=ShouldExcludePath) |
| 78 finally: |
| 79 archive.close() |
| 80 | 80 |
| 81 return 0 | 81 return 0 |
| 82 | 82 |
| 83 if __name__ == "__main__": | 83 if __name__ == "__main__": |
| 84 sys.exit(main(sys.argv[1:])) | 84 sys.exit(main(sys.argv[1:])) |
| OLD | NEW |