Enable password generation only if sync for passwords is enabled.
[chromium-blink-merge.git] / tools / export_tarball / export_tarball.py
blob861503eec64991bd88b1f6cfa8f0e84e16babbc1
1 #!/usr/bin/env python
2 # Copyright (c) 2011 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.
6 """
7 This tool creates a tarball with all the sources, but without .svn directories.
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).
12 Example usage:
14 export_tarball.py /foo/bar
16 The above will create file /foo/bar.tar.bz2.
17 """
19 import optparse
20 import os
21 import subprocess
22 import sys
23 import tarfile
26 NONESSENTIAL_DIRS = (
27 'chrome/common/extensions/docs',
28 'chrome/test/data',
29 'chrome/tools/test/reference_build',
30 'courgette/testdata',
31 'data',
32 'native_client/src/trusted/service_runtime/testdata',
33 'src/chrome/test/data',
34 'o3d/documentation',
35 'o3d/samples',
36 'o3d/tests',
37 'third_party/angle/samples/gles2_book',
38 'third_party/hunspell_dictionaries',
39 'third_party/hunspell/tests',
40 'third_party/lighttpd',
41 'third_party/sqlite/test',
42 'third_party/vc_80',
43 'third_party/xdg-utils/tests',
44 'third_party/yasm/source/patched-yasm/modules/arch/x86/tests',
45 'third_party/yasm/source/patched-yasm/modules/dbgfmts/dwarf2/tests',
46 'third_party/yasm/source/patched-yasm/modules/objfmts/bin/tests',
47 'third_party/yasm/source/patched-yasm/modules/objfmts/coff/tests',
48 'third_party/yasm/source/patched-yasm/modules/objfmts/elf/tests',
49 'third_party/yasm/source/patched-yasm/modules/objfmts/macho/tests',
50 'third_party/yasm/source/patched-yasm/modules/objfmts/rdf/tests',
51 'third_party/yasm/source/patched-yasm/modules/objfmts/win32/tests',
52 'third_party/yasm/source/patched-yasm/modules/objfmts/win64/tests',
53 'third_party/yasm/source/patched-yasm/modules/objfmts/xdf/tests',
54 'third_party/WebKit/Source/JavaScriptCore/tests',
55 'third_party/WebKit/LayoutTests',
56 'v8/test',
57 'webkit/data/layout_tests',
58 'webkit/tools/test/reference_build',
62 def GetSourceDirectory():
63 return os.path.realpath(
64 os.path.join(os.path.dirname(__file__), '..', '..', '..', 'src'))
67 # Workaround lack of the exclude parameter in add method in python-2.4.
68 # TODO(phajdan.jr): remove the workaround when it's not needed on the bot.
69 class MyTarFile(tarfile.TarFile):
70 def set_remove_nonessential_files(self, remove):
71 self.__remove_nonessential_files = remove
73 def add(self, name, arcname=None, recursive=True, exclude=None):
74 head, tail = os.path.split(name)
75 if tail in ('.svn', '.git'):
76 return
78 if self.__remove_nonessential_files:
79 for nonessential_dir in NONESSENTIAL_DIRS:
80 dir_path = os.path.join(GetSourceDirectory(), nonessential_dir)
81 if name.startswith(dir_path):
82 return
84 tarfile.TarFile.add(self, name, arcname=arcname, recursive=recursive)
87 def main(argv):
88 parser = optparse.OptionParser()
89 parser.add_option("--remove-nonessential-files",
90 dest="remove_nonessential_files",
91 action="store_true", default=False)
93 options, args = parser.parse_args(argv)
95 if len(args) != 1:
96 print 'You must provide only one argument: output file name'
97 print '(without .tar.bz2 extension).'
98 return 1
100 if not os.path.exists(GetSourceDirectory()):
101 print 'Cannot find the src directory.'
102 return 1
104 output_fullname = args[0] + '.tar.bz2'
105 output_basename = os.path.basename(args[0])
107 archive = MyTarFile.open(output_fullname, 'w:bz2')
108 archive.set_remove_nonessential_files(options.remove_nonessential_files)
109 try:
110 archive.add(GetSourceDirectory(), arcname=output_basename)
111 finally:
112 archive.close()
114 return 0
117 if __name__ == "__main__":
118 sys.exit(main(sys.argv[1:]))