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

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

Issue 661182: Merge 39238 - Fix removing unnecessary files in export_tarball.py... (Closed) Base URL: svn://svn.chromium.org/chrome/branches/307/src/
Patch Set: Created 10 years, 9 months 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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).
(...skipping 23 matching lines...) Expand all
34 'webkit/tools/test/reference_build', 34 'webkit/tools/test/reference_build',
35 ) 35 )
36 36
37 def GetSourceDirectory(): 37 def GetSourceDirectory():
38 return os.path.realpath( 38 return os.path.realpath(
39 os.path.join(os.path.dirname(__file__), '..', '..', '..', 'src')) 39 os.path.join(os.path.dirname(__file__), '..', '..', '..', 'src'))
40 40
41 # Workaround lack of the exclude parameter in add method in python-2.4. 41 # Workaround lack of the exclude parameter in add method in python-2.4.
42 # TODO(phajdan.jr): remove the workaround when it's not needed on the bot. 42 # TODO(phajdan.jr): remove the workaround when it's not needed on the bot.
43 class MyTarFile(tarfile.TarFile): 43 class MyTarFile(tarfile.TarFile):
44 def set_remove_nonessential_files(self, remove):
45 self.__remove_nonessential_files = remove
46
44 def add(self, name, arcname=None, recursive=True, exclude=None): 47 def add(self, name, arcname=None, recursive=True, exclude=None):
45 if exclude is not None and exclude(name): 48 head, tail = os.path.split(name)
49 if tail in ('.svn', '.git'):
46 return 50 return
51
52 if self.__remove_nonessential_files:
53 for nonessential_dir in NONESSENTIAL_DIRS:
54 dir_path = os.path.join(GetSourceDirectory(), nonessential_dir)
55 if name.startswith(dir_path):
56 return
57
47 tarfile.TarFile.add(self, name, arcname=arcname, recursive=recursive) 58 tarfile.TarFile.add(self, name, arcname=arcname, recursive=recursive)
48 59
49 def main(argv): 60 def main(argv):
50 parser = optparse.OptionParser() 61 parser = optparse.OptionParser()
51 parser.add_option("--remove-nonessential-files", 62 parser.add_option("--remove-nonessential-files",
52 dest="remove_nonessential_files", 63 dest="remove_nonessential_files",
53 action="store_true", default=False) 64 action="store_true", default=False)
54 65
55 options, args = parser.parse_args(argv) 66 options, args = parser.parse_args(argv)
56 67
57 if len(args) != 1: 68 if len(args) != 1:
58 print 'You must provide only one argument: output file name' 69 print 'You must provide only one argument: output file name'
59 print '(without .tar.bz2 extension).' 70 print '(without .tar.bz2 extension).'
60 return 1 71 return 1
61 72
62 if not os.path.exists(GetSourceDirectory()): 73 if not os.path.exists(GetSourceDirectory()):
63 print 'Cannot find the src directory.' 74 print 'Cannot find the src directory.'
64 return 1 75 return 1
65 76
66 output_fullname = args[0] + '.tar.bz2' 77 output_fullname = args[0] + '.tar.bz2'
67 output_basename = os.path.basename(args[0]) 78 output_basename = os.path.basename(args[0])
68 79
69 def ShouldExcludePath(path):
70 head, tail = os.path.split(path)
71 if tail in ('.svn', '.git'):
72 return True
73
74 if not options.remove_nonessential_files:
75 return False
76 for nonessential_dir in NONESSENTIAL_DIRS:
77 if path.startswith(os.path.join(GetSourceDirectory(), nonessential_dir)):
78 return True
79
80 return False
81
82 archive = MyTarFile.open(output_fullname, 'w:bz2') 80 archive = MyTarFile.open(output_fullname, 'w:bz2')
81 archive.set_remove_nonessential_files(options.remove_nonessential_files)
83 try: 82 try:
84 archive.add(GetSourceDirectory(), arcname=output_basename, 83 archive.add(GetSourceDirectory(), arcname=output_basename)
85 exclude=ShouldExcludePath)
86 finally: 84 finally:
87 archive.close() 85 archive.close()
88 86
89 return 0 87 return 0
90 88
91 if __name__ == "__main__": 89 if __name__ == "__main__":
92 sys.exit(main(sys.argv[1:])) 90 sys.exit(main(sys.argv[1:]))
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698