Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
|
Dirk Pranke
2016/01/29 21:01:56
Is this script actually used somewhere? Can we use
brettw
2016/01/29 21:10:21
You can see in a previous patch I removed this, an
Dirk Pranke
2016/01/29 21:38:42
Mike, can you help us figure out if this is needed
brettw
2016/01/29 21:48:15
I filed a bug https://code.google.com/p/chromium/i
msw
2016/01/29 21:59:38
I don't have any useful offhand knowledge here, bu
| |
| 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 | |
| 11 import optparse | 10 import optparse |
| 12 import os | 11 import os |
| 13 import sys | 12 import sys |
| 14 import zipfile | 13 import zipfile |
| 15 | 14 |
| 15 sys.path.append(os.path.join(os.path.dirname(__file__), | |
| 16 os.pardir, os.pardir, os.pardir, os.pardir, | |
| 17 "build")) | |
| 18 import gn_helpers | |
| 19 | |
| 16 def DoZip(inputs, link_inputs, zip_inputs, output, base_dir): | 20 def DoZip(inputs, link_inputs, zip_inputs, output, base_dir): |
| 17 files = [] | 21 files = [] |
| 18 with zipfile.ZipFile(output, 'w', zipfile.ZIP_DEFLATED) as outfile: | 22 with zipfile.ZipFile(output, 'w', zipfile.ZIP_DEFLATED) as outfile: |
| 19 for f in inputs: | 23 for f in inputs: |
| 20 file_name = os.path.relpath(f, base_dir) | 24 file_name = os.path.relpath(f, base_dir) |
| 21 files.append(file_name) | 25 files.append(file_name) |
| 22 outfile.write(f, file_name) | 26 outfile.write(f, file_name) |
| 23 for f in link_inputs: | 27 for f in link_inputs: |
| 24 realf = os.path.realpath(f) # Resolve symlinks. | 28 realf = os.path.realpath(f) # Resolve symlinks. |
| 25 file_name = os.path.relpath(realf, base_dir) | 29 file_name = os.path.relpath(realf, base_dir) |
| 26 files.append(file_name) | 30 files.append(file_name) |
| 27 outfile.write(realf, file_name) | 31 outfile.write(realf, file_name) |
| 28 for zf_name in zip_inputs: | 32 for zf_name in zip_inputs: |
| 29 with zipfile.ZipFile(zf_name, 'r') as zf: | 33 with zipfile.ZipFile(zf_name, 'r') as zf: |
| 30 for f in zf.namelist(): | 34 for f in zf.namelist(): |
| 31 if f not in files: | 35 if f not in files: |
| 32 files.append(f) | 36 files.append(f) |
| 33 with zf.open(f) as zff: | 37 with zf.open(f) as zff: |
| 34 outfile.writestr(f, zff.read()) | 38 outfile.writestr(f, zff.read()) |
| 35 | 39 |
| 36 | 40 |
| 37 def main(): | 41 def main(): |
| 38 parser = optparse.OptionParser() | 42 parser = optparse.OptionParser() |
| 39 | 43 |
| 40 parser.add_option('--inputs', help='List of files to archive.') | 44 parser.add_option('--inputs', |
| 45 help='GN format list of files to archive.') | |
| 41 parser.add_option('--link-inputs', | 46 parser.add_option('--link-inputs', |
| 42 help='List of files to archive. Symbolic links are resolved.') | 47 help='GN-format list of files to archive. Symbolic links are resolved.') |
| 43 parser.add_option('--zip-inputs', help='List of zip files to re-archive.') | 48 parser.add_option('--zip-inputs', |
| 49 help='GN-format list of zip files to re-archive.') | |
| 44 parser.add_option('--output', help='Path to output archive.') | 50 parser.add_option('--output', help='Path to output archive.') |
| 45 parser.add_option('--base-dir', | 51 parser.add_option('--base-dir', |
| 46 help='If provided, the paths in the archive will be ' | 52 help='If provided, the paths in the archive will be ' |
| 47 'relative to this directory', default='.') | 53 'relative to this directory', default='.') |
| 48 | 54 |
| 49 options, _ = parser.parse_args() | 55 options, _ = parser.parse_args() |
| 50 | 56 |
| 51 inputs = [] | 57 inputs = [] |
| 52 if (options.inputs): | 58 if (options.inputs): |
| 53 inputs = ast.literal_eval(options.inputs) | 59 parser = gn_helpers.GNValueParser(options.inputs) |
| 60 inputs = parser.ParseList() | |
| 61 | |
| 54 link_inputs = [] | 62 link_inputs = [] |
| 55 if options.link_inputs: | 63 if options.link_inputs: |
| 56 link_inputs = ast.literal_eval(options.link_inputs) | 64 parser = gn_helpers.GNValueParser(options.link_inputs) |
| 65 link_inputs = parser.ParseList() | |
| 66 | |
| 57 zip_inputs = [] | 67 zip_inputs = [] |
| 58 if options.zip_inputs: | 68 if options.zip_inputs: |
| 59 zip_inputs = ast.literal_eval(options.zip_inputs) | 69 parser = gn_helpers.GNValueParser(options.zip_inputs) |
| 70 zip_inputs = parser.ParseList() | |
| 71 | |
| 60 output = options.output | 72 output = options.output |
| 61 base_dir = options.base_dir | 73 base_dir = options.base_dir |
| 62 | 74 |
| 63 DoZip(inputs, link_inputs, zip_inputs, output, base_dir) | 75 DoZip(inputs, link_inputs, zip_inputs, output, base_dir) |
| 64 | 76 |
| 65 if __name__ == '__main__': | 77 if __name__ == '__main__': |
| 66 sys.exit(main()) | 78 sys.exit(main()) |
| OLD | NEW |