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

Side by Side Diff: mojo/public/tools/gn/zip.py

Issue 796373006: Content handler for python. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 11 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
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # 2 #
3 # Copyright 2014 The Chromium Authors. All rights reserved. 3 # Copyright 2014 The Chromium Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be 4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file. 5 # found in the LICENSE file.
6 6
7 """Archives a set of files. 7 """Archives a set of files.
8 """ 8 """
9 9
10 import ast 10 import ast
11 import optparse 11 import optparse
12 import os 12 import os
13 import sys 13 import sys
14 import zipfile 14 import zipfile
15 15
16 sys.path.append(os.path.join(os.path.dirname(__file__), os.pardir, 'gyp')) 16 def DoZip(inputs, zip_inputs, output, base_dir):
17 from util import build_utils 17 files = []
18
19 def DoZip(inputs, output, base_dir):
20 with zipfile.ZipFile(output, 'w') as outfile: 18 with zipfile.ZipFile(output, 'w') as outfile:
21 for f in inputs: 19 for f in inputs:
22 outfile.write(f, os.path.relpath(f, base_dir)) 20 file_name = os.path.relpath(f, base_dir)
21 files.append(file_name)
22 outfile.write(f, file_name)
23 for zf_name in zip_inputs:
24 with zipfile.ZipFile(zf_name, 'r') as zf:
25 for f in zf.namelist():
26 if f not in files:
27 files.append(f)
28 with zf.open(f) as zff:
29 outfile.writestr(f, zff.read())
30
23 31
24 def main(): 32 def main():
25 parser = optparse.OptionParser() 33 parser = optparse.OptionParser()
26 build_utils.AddDepfileOption(parser)
27 34
28 parser.add_option('--inputs', help='List of files to archive.') 35 parser.add_option('--inputs', help='List of files to archive.')
36 parser.add_option('--zip-inputs', help='List of zip files to re-archive.')
29 parser.add_option('--output', help='Path to output archive.') 37 parser.add_option('--output', help='Path to output archive.')
30 parser.add_option('--base-dir', 38 parser.add_option('--base-dir',
31 help='If provided, the paths in the archive will be ' 39 help='If provided, the paths in the archive will be '
32 'relative to this directory', default='.') 40 'relative to this directory', default='.')
33 41
34 options, _ = parser.parse_args() 42 options, _ = parser.parse_args()
35 43
36 inputs = ast.literal_eval(options.inputs) 44 inputs = ast.literal_eval(options.inputs)
45 zip_inputs = []
46 if options.zip_inputs:
47 zip_inputs = ast.literal_eval(options.zip_inputs)
37 output = options.output 48 output = options.output
38 base_dir = options.base_dir 49 base_dir = options.base_dir
39 50
40 DoZip(inputs, output, base_dir) 51 DoZip(inputs, zip_inputs, output, base_dir)
41
42 if options.depfile:
43 build_utils.WriteDepfile(
44 options.depfile,
45 build_utils.GetPythonDependencies())
46
47 52
48 if __name__ == '__main__': 53 if __name__ == '__main__':
49 sys.exit(main()) 54 sys.exit(main())
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698