Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(73)

Side by Side Diff: tools/export_tarball/export_tarball.py

Issue 8678023: Fix python scripts in src/tools/ (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixes Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 #!/usr/bin/python 1 #!/usr/bin/env python
2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. 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 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 import optparse 19 import optparse
20 import os 20 import os
21 import subprocess 21 import subprocess
22 import sys 22 import sys
23 import tarfile 23 import tarfile
24 24
25
25 NONESSENTIAL_DIRS = ( 26 NONESSENTIAL_DIRS = (
26 'chrome/common/extensions/docs', 27 'chrome/common/extensions/docs',
27 'chrome/test/data', 28 'chrome/test/data',
28 'chrome/tools/test/reference_build', 29 'chrome/tools/test/reference_build',
29 'courgette/testdata', 30 'courgette/testdata',
30 'data', 31 'data',
31 'native_client/src/trusted/service_runtime/testdata', 32 'native_client/src/trusted/service_runtime/testdata',
32 'src/chrome/test/data', 33 'src/chrome/test/data',
33 'o3d/documentation', 34 'o3d/documentation',
34 'o3d/samples', 35 'o3d/samples',
(...skipping 15 matching lines...) Expand all
50 'third_party/yasm/source/patched-yasm/modules/objfmts/win32/tests', 51 'third_party/yasm/source/patched-yasm/modules/objfmts/win32/tests',
51 'third_party/yasm/source/patched-yasm/modules/objfmts/win64/tests', 52 'third_party/yasm/source/patched-yasm/modules/objfmts/win64/tests',
52 'third_party/yasm/source/patched-yasm/modules/objfmts/xdf/tests', 53 'third_party/yasm/source/patched-yasm/modules/objfmts/xdf/tests',
53 'third_party/WebKit/Source/JavaScriptCore/tests', 54 'third_party/WebKit/Source/JavaScriptCore/tests',
54 'third_party/WebKit/LayoutTests', 55 'third_party/WebKit/LayoutTests',
55 'v8/test', 56 'v8/test',
56 'webkit/data/layout_tests', 57 'webkit/data/layout_tests',
57 'webkit/tools/test/reference_build', 58 'webkit/tools/test/reference_build',
58 ) 59 )
59 60
61
60 def GetSourceDirectory(): 62 def GetSourceDirectory():
61 return os.path.realpath( 63 return os.path.realpath(
62 os.path.join(os.path.dirname(__file__), '..', '..', '..', 'src')) 64 os.path.join(os.path.dirname(__file__), '..', '..', '..', 'src'))
63 65
66
64 # Workaround lack of the exclude parameter in add method in python-2.4. 67 # Workaround lack of the exclude parameter in add method in python-2.4.
65 # TODO(phajdan.jr): remove the workaround when it's not needed on the bot. 68 # TODO(phajdan.jr): remove the workaround when it's not needed on the bot.
66 class MyTarFile(tarfile.TarFile): 69 class MyTarFile(tarfile.TarFile):
67 def set_remove_nonessential_files(self, remove): 70 def set_remove_nonessential_files(self, remove):
68 self.__remove_nonessential_files = remove 71 self.__remove_nonessential_files = remove
69 72
70 def add(self, name, arcname=None, recursive=True, exclude=None): 73 def add(self, name, arcname=None, recursive=True, exclude=None):
71 head, tail = os.path.split(name) 74 head, tail = os.path.split(name)
72 if tail in ('.svn', '.git'): 75 if tail in ('.svn', '.git'):
73 return 76 return
74 77
75 if self.__remove_nonessential_files: 78 if self.__remove_nonessential_files:
76 for nonessential_dir in NONESSENTIAL_DIRS: 79 for nonessential_dir in NONESSENTIAL_DIRS:
77 dir_path = os.path.join(GetSourceDirectory(), nonessential_dir) 80 dir_path = os.path.join(GetSourceDirectory(), nonessential_dir)
78 if name.startswith(dir_path): 81 if name.startswith(dir_path):
79 return 82 return
80 83
81 tarfile.TarFile.add(self, name, arcname=arcname, recursive=recursive) 84 tarfile.TarFile.add(self, name, arcname=arcname, recursive=recursive)
82 85
86
83 def main(argv): 87 def main(argv):
84 parser = optparse.OptionParser() 88 parser = optparse.OptionParser()
85 parser.add_option("--remove-nonessential-files", 89 parser.add_option("--remove-nonessential-files",
86 dest="remove_nonessential_files", 90 dest="remove_nonessential_files",
87 action="store_true", default=False) 91 action="store_true", default=False)
88 92
89 options, args = parser.parse_args(argv) 93 options, args = parser.parse_args(argv)
90 94
91 if len(args) != 1: 95 if len(args) != 1:
92 print 'You must provide only one argument: output file name' 96 print 'You must provide only one argument: output file name'
93 print '(without .tar.bz2 extension).' 97 print '(without .tar.bz2 extension).'
94 return 1 98 return 1
95 99
96 if not os.path.exists(GetSourceDirectory()): 100 if not os.path.exists(GetSourceDirectory()):
97 print 'Cannot find the src directory.' 101 print 'Cannot find the src directory.'
98 return 1 102 return 1
99 103
100 output_fullname = args[0] + '.tar.bz2' 104 output_fullname = args[0] + '.tar.bz2'
101 output_basename = os.path.basename(args[0]) 105 output_basename = os.path.basename(args[0])
102 106
103 archive = MyTarFile.open(output_fullname, 'w:bz2') 107 archive = MyTarFile.open(output_fullname, 'w:bz2')
104 archive.set_remove_nonessential_files(options.remove_nonessential_files) 108 archive.set_remove_nonessential_files(options.remove_nonessential_files)
105 try: 109 try:
106 archive.add(GetSourceDirectory(), arcname=output_basename) 110 archive.add(GetSourceDirectory(), arcname=output_basename)
107 finally: 111 finally:
108 archive.close() 112 archive.close()
109 113
110 return 0 114 return 0
111 115
116
112 if __name__ == "__main__": 117 if __name__ == "__main__":
113 sys.exit(main(sys.argv[1:])) 118 sys.exit(main(sys.argv[1:]))
OLDNEW
« no previous file with comments | « tools/dromaeo_benchmark_runner/dromaeo_benchmark_runner.py ('k') | tools/export_tarball/export_v8_tarball.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698