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

Side by Side Diff: chrome/tools/build/win/make_policy_zip.py

Issue 8680018: Fix python scripts in src/chrome/ (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: copyright 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
« no previous file with comments | « chrome/tools/build/win/dependencies.py ('k') | chrome/tools/build/win/scan_server_dlls.py » ('j') | 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/env python
1 # Copyright (c) 2011 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 # 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
3 # found in the LICENSE file. 4 # found in the LICENSE file.
4 5
5 """Creates a zip archive with policy template files. The list of input files is 6 """Creates a zip archive with policy template files. The list of input files is
6 extracted from a grd file with grit. This is to keep the length of input 7 extracted from a grd file with grit. This is to keep the length of input
7 arguments below the limit on Windows. 8 arguments below the limit on Windows.
8 """ 9 """
9 10
10 import optparse 11 import optparse
11 import os 12 import os
12 import sys 13 import sys
13 import zipfile 14 import zipfile
14 15
16
15 def add_files_to_zip(zip_file, base_dir, file_list): 17 def add_files_to_zip(zip_file, base_dir, file_list):
16 """Pack a list of files into a zip archive, that is already 18 """Pack a list of files into a zip archive, that is already
17 opened for writing. 19 opened for writing.
18 20
19 Args: 21 Args:
20 zip_file: An object representing the zip archive. 22 zip_file: An object representing the zip archive.
21 base_dir: Base path of all the files in the real file system. 23 base_dir: Base path of all the files in the real file system.
22 files: List of file paths to add, all relative to base_dir. 24 files: List of file paths to add, all relative to base_dir.
23 The zip entries will only contain this componenet of the path. 25 The zip entries will only contain this componenet of the path.
24 """ 26 """
25 for file_path in file_list: 27 for file_path in file_list:
26 zip_file.write(base_dir + file_path, file_path) 28 zip_file.write(base_dir + file_path, file_path)
27 return 0 29 return 0
28 30
31
29 def get_grd_outputs(grit_cmd, grit_defines, grd_file, grd_strip_path_prefix): 32 def get_grd_outputs(grit_cmd, grit_defines, grd_file, grd_strip_path_prefix):
30 grit_path = os.path.join(os.getcwd(), os.path.dirname(grit_cmd)) 33 grit_path = os.path.join(os.getcwd(), os.path.dirname(grit_cmd))
31 sys.path.append(grit_path) 34 sys.path.append(grit_path)
32 import grit_info 35 import grit_info
33 outputs = grit_info.Outputs(grd_file, grit_defines) 36 outputs = grit_info.Outputs(grd_file, grit_defines)
34 result = [] 37 result = []
35 for item in outputs: 38 for item in outputs:
36 assert item.startswith(grd_strip_path_prefix) 39 assert item.startswith(grd_strip_path_prefix)
37 result.append(item[len(grd_strip_path_prefix):]) 40 result.append(item[len(grd_strip_path_prefix):])
38 return result 41 return result
39 42
43
40 def main(argv): 44 def main(argv):
41 """Pack a list of files into a zip archive. 45 """Pack a list of files into a zip archive.
42 46
43 Args: 47 Args:
44 zip_path: The file name of the zip archive. 48 zip_path: The file name of the zip archive.
45 base_dir: Base path of input files. 49 base_dir: Base path of input files.
46 locales: The list of locales that are used to generate the list of file 50 locales: The list of locales that are used to generate the list of file
47 names using INPUT_FILES. 51 names using INPUT_FILES.
48 """ 52 """
49 parser = optparse.OptionParser() 53 parser = optparse.OptionParser()
(...skipping 16 matching lines...) Expand all
66 70
67 file_list = options.extra_input 71 file_list = options.extra_input
68 file_list += get_grd_outputs(options.grit_info, grit_defines, 72 file_list += get_grd_outputs(options.grit_info, grit_defines,
69 options.grd_input, options.grd_strip_path_prefix) 73 options.grd_input, options.grd_strip_path_prefix)
70 zip_file = zipfile.ZipFile(options.output, 'w', zipfile.ZIP_DEFLATED) 74 zip_file = zipfile.ZipFile(options.output, 'w', zipfile.ZIP_DEFLATED)
71 try: 75 try:
72 return add_files_to_zip(zip_file, options.basedir, file_list) 76 return add_files_to_zip(zip_file, options.basedir, file_list)
73 finally: 77 finally:
74 zip_file.close() 78 zip_file.close()
75 79
80
76 if '__main__' == __name__: 81 if '__main__' == __name__:
77 sys.exit(main(sys.argv)) 82 sys.exit(main(sys.argv))
78
OLDNEW
« no previous file with comments | « chrome/tools/build/win/dependencies.py ('k') | chrome/tools/build/win/scan_server_dlls.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698