summaryrefslogtreecommitdiffstats
path: root/tools/export_tarball
diff options
context:
space:
mode:
authorphajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-23 15:34:41 +0000
committerphajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-23 15:34:41 +0000
commit757c492255aa75af8ac76986c67404c68af08def (patch)
treeb9726932cc034543d5ad4c83bcbf9e9f1a45e429 /tools/export_tarball
parent38e3bfc698fa094d1e501479e5ebf1c9f220c55b (diff)
downloadchromium_src-757c492255aa75af8ac76986c67404c68af08def.zip
chromium_src-757c492255aa75af8ac76986c67404c68af08def.tar.gz
chromium_src-757c492255aa75af8ac76986c67404c68af08def.tar.bz2
Add export_tarball tool.
It creates a .bz2 tarball with all the sources, but without .svn directories, and has an option to remove files which are not required for build, and take a lot of space. Review URL: http://codereview.chromium.org/155863 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@21384 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'tools/export_tarball')
-rw-r--r--tools/export_tarball/export_tarball.py90
1 files changed, 90 insertions, 0 deletions
diff --git a/tools/export_tarball/export_tarball.py b/tools/export_tarball/export_tarball.py
new file mode 100644
index 0000000..79cc4fa
--- /dev/null
+++ b/tools/export_tarball/export_tarball.py
@@ -0,0 +1,90 @@
+#!/usr/bin/python
+# Copyright (c) 2009 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+"""
+This tool creates a tarball with all the sources, but without .svn directories.
+
+It can also remove files which are not strictly required for build, so that
+the resulting tarball can be reasonably small (last time it was ~110 MB).
+
+Example usage (make sure gclient is in your PATH):
+
+export_tarball.py /foo/bar
+
+The above will create file /foo/bar.tar.bz2.
+"""
+
+from __future__ import with_statement
+
+import contextlib
+import optparse
+import os
+import shutil
+import subprocess
+import sys
+import tarfile
+import tempfile
+
+def RunCommand(argv):
+ """Runs the command with given argv and returns exit code."""
+ try:
+ proc = subprocess.Popen(argv, stdout=None)
+ except OSError:
+ return 1
+ output = proc.communicate()[0]
+ return proc.returncode
+
+def main(argv):
+ parser = optparse.OptionParser()
+ parser.add_option("--remove-nonessential-files",
+ dest="remove_nonessential_files",
+ action="store_true", default=False)
+
+ options, args = parser.parse_args(argv)
+
+ if len(args) != 1:
+ print 'You must provide only one argument: output file name'
+ print '(without .tar.bz2 extension).'
+ return 1
+
+ output_fullname = args[0] + '.tar.bz2'
+ output_basename = os.path.basename(args[0])
+ target_dir = tempfile.mkdtemp()
+
+ try:
+ if RunCommand(['gclient', 'export', target_dir]) != 0:
+ print 'gclient failed'
+ return 1
+
+ if options.remove_nonessential_files:
+ nonessential_dirs = (
+ 'src/chrome/test/data',
+ 'src/chrome/tools/test/reference_build',
+ 'src/gears/binaries',
+ 'src/net/data/cache_tests',
+ 'src/o3d/documentation',
+ 'src/o3d/samples',
+ 'src/third_party/lighttpd',
+ 'src/third_party/WebKit/LayoutTests',
+ 'src/webkit/data/layout_tests',
+ 'src/webkit/tools/test/reference_build',
+ )
+ for dir in nonessential_dirs:
+ path = os.path.join(target_dir, dir)
+ try:
+ print 'removing %s...' % dir
+ shutil.rmtree(path)
+ except OSError, e:
+ print 'error while trying to remove %s, skipping' % dir
+
+ with contextlib.closing(tarfile.open(output_fullname, 'w:bz2')) as archive:
+ archive.add(os.path.join(target_dir, 'src'), arcname=output_basename)
+ finally:
+ shutil.rmtree(target_dir)
+
+ return 0
+
+if __name__ == "__main__":
+ sys.exit(main(sys.argv[1:]))