Index: chrome/tools/build/win/make_policy_zip.py |
diff --git a/chrome/tools/build/win/make_policy_zip.py b/chrome/tools/build/win/make_policy_zip.py |
new file mode 100644 |
index 0000000000000000000000000000000000000000..8461e5a166a68912479fdee3a93acb7e8379eaeb |
--- /dev/null |
+++ b/chrome/tools/build/win/make_policy_zip.py |
@@ -0,0 +1,81 @@ |
+# Copyright (c) 2011 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 policy template files. The list of input files is |
+specified by the list of available translations. This is to keep the length of |
+input arguments below the limit on Windows. |
+""" |
+ |
+import sys |
+import zipfile |
+ |
+# The following list specifies the files to be archived. Items containing the |
+# substring ZZLOCALE will be replicated for each specified locale with ZZLOCALE |
+# replaced with the respective locale. |
+FILE_NAME_PATTERNS = [ |
+ 'VERSION', |
+ # The following elements of the list should be in sync with the outputs |
+ # specified for Windows in app/policy/policy_templates.grd |
tony
2011/05/19 18:49:24
Hmm, is it possible for you to import tools/grit/g
gfeher
2011/05/20 20:32:48
It required hacking, but I guess it worthed it. Do
|
+ 'linux/examples/chrome.json', |
+ 'windows/examples/chrome.reg', |
+ 'windows/admx/chrome.admx', |
+ 'windows/admx/ZZLOCALE/chrome.adml', |
+ 'windows/adm/ZZLOCALE/chrome.adm', |
+ 'common/html/ZZLOCALE/chrome_policy_list.html', |
+] |
+ |
+def add_files_to_zip(zip_file, base_dir, file_list): |
+ """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: Base path of all the files in the real file system. |
+ files: List of file paths to add, all relative to base_dir. |
+ The zip entries will only contain this componenet of the path. |
+ """ |
+ for file_path in file_list: |
+ zip_file.write(base_dir + file_path, file_path) |
+ return 0 |
+ |
+def locales_to_file_names(file_name_patterns, locales): |
+ """Combines |file_name_patterns| and |locales| into a list of file paths. |
+ Each entry in file_name_patterns containing the substring ZZLOCALE will |
+ be included in the result for each locale with ZZLOCALE replaced with |
+ the respective locale. |
+ """ |
+ result = [] |
+ for f in file_name_patterns: |
+ if 'ZZLOCALE' in f: |
+ for locale in locales: |
+ result.append(f.replace('ZZLOCALE', locale)) |
+ else: |
+ result.append(f) |
+ return result |
+ |
+def main(zip_path, base_dir, locales): |
+ """Pack a list of files into a zip archive. |
+ |
+ Args: |
+ zip_path: The file name of the zip archive. |
+ base_dir: Base path of input files. |
+ locales: The list of locales that are used to generate the list of file |
+ names using INPUT_FILES. |
+ """ |
+ if (base_dir[-1] != '/'): |
+ base_dir = base_dir + '/' |
+ |
+ file_list = locales_to_file_names(FILE_NAME_PATTERNS, locales) |
+ zip_file = zipfile.ZipFile(zip_path, 'w', zipfile.ZIP_DEFLATED) |
+ try: |
+ return add_files_to_zip(zip_file, base_dir, file_list) |
+ finally: |
+ zip_file.close() |
+ |
+if '__main__' == __name__: |
+ if len(sys.argv) < 4: |
+ print "usage: %s output.zip path/to/base/dir list of locales" % sys.argv[0] |
+ sys.exit(1) |
+ |
+ sys.exit(main(sys.argv[1], sys.argv[2], sys.argv[3:])) |