summaryrefslogtreecommitdiffstats
path: root/chrome/tools/build
diff options
context:
space:
mode:
authorgfeher@chromium.org <gfeher@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-07 09:32:07 +0000
committergfeher@chromium.org <gfeher@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-07 09:32:07 +0000
commit2b0c07b00d99cbc626121095376ce1719d2eca85 (patch)
treed1e15c6da25b49646e292ceb15b465c67562f0ee /chrome/tools/build
parent1fc6d8197182480b0efd952d4cdce0df6755a245 (diff)
downloadchromium_src-2b0c07b00d99cbc626121095376ce1719d2eca85.zip
chromium_src-2b0c07b00d99cbc626121095376ce1719d2eca85.tar.gz
chromium_src-2b0c07b00d99cbc626121095376ce1719d2eca85.tar.bz2
Create a zip archive of generated policy templates on Windows
The plan is to generate this zip later on an official buildbot, and publish it with stage_build.py. BUG=57805 TEST=none Review URL: http://codereview.chromium.org/3564008 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@61776 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/tools/build')
-rw-r--r--chrome/tools/build/win/make_zip_with_relative_entries.py63
1 files changed, 63 insertions, 0 deletions
diff --git a/chrome/tools/build/win/make_zip_with_relative_entries.py b/chrome/tools/build/win/make_zip_with_relative_entries.py
new file mode 100644
index 0000000..4df554e
--- /dev/null
+++ b/chrome/tools/build/win/make_zip_with_relative_entries.py
@@ -0,0 +1,63 @@
+# Copyright (c) 2010 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.
+
+"""Creates a zip archive with relative entry paths, from a list of files with
+absolute paths.
+"""
+
+import sys
+import zipfile
+
+def add_files_to_zip(zip_file, base_dir, files):
+ """Pack a list of files into a zip archive, that is already
+ opened for writing.
+
+ Args:
+ zip_file: An object representing the zip archive.
+ base_dir: A path that will be stripped from the beginning of the paths of
+ added files.
+ files: The list of file paths to add.
+ """
+ prefix_len = len(base_dir)
+
+ for file_path in files:
+ if not file_path.startswith(base_dir):
+ print "All the input files should be in the base directory."
+ return 1
+ entry_path = file_path[prefix_len:]
+ zip_file.write(file_path, entry_path)
+
+ return 0
+
+
+def main(zip_path, base_dir, files):
+ """Pack a list of files into a zip archive.
+
+ Args:
+ zip_path: The file name of the zip archive.
+ base_dir: A path that will be stripped from the beginning of the paths of
+ added files.
+ files: The list of file paths to add.
+
+ Example:
+ main('x.zip', '/a/b', ['/a/b/c/1.txt', '/a/b/d/2.txt'])
+ Will put the following entries to x.zip:
+ c/1.txt
+ d/2.txt
+ """
+ if (base_dir[-1] != '/'):
+ base_dir = base_dir + '/'
+
+ zip_file = zipfile.ZipFile(zip_path, 'w', zipfile.ZIP_DEFLATED)
+ try:
+ return add_files_to_zip(zip_file, base_dir, files)
+ finally:
+ zip_file.close()
+
+if '__main__' == __name__:
+ if len(sys.argv) < 4:
+ print "usage: %s output.zip path/to/base/dir list of files" % sys.argv[0]
+ sys.exit(1)
+
+ sys.exit(main(sys.argv[1], sys.argv[2], sys.argv[3:]))