| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 # Copyright 2016 The Chromium Authors. All rights reserved. | 2 # Copyright 2016 The Chromium Authors. All rights reserved. |
| 3 # 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 |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 """ | 6 """ |
| 7 Convert the ASCII download_file_types.asciipb proto into a binary resource. | 7 Convert the ASCII download_file_types.asciipb proto into a binary resource. |
| 8 """ | 8 """ |
| 9 | 9 |
| 10 import optparse | 10 import optparse |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 ifile.close() | 28 ifile.close() |
| 29 | 29 |
| 30 # Parse it into a structure PB | 30 # Parse it into a structure PB |
| 31 pb = config_pb2.DownloadFileTypeConfig() | 31 pb = config_pb2.DownloadFileTypeConfig() |
| 32 text_format.Merge(ascii_pb_str, pb) | 32 text_format.Merge(ascii_pb_str, pb) |
| 33 | 33 |
| 34 # Serialize it | 34 # Serialize it |
| 35 binary_pb_str = pb.SerializeToString() | 35 binary_pb_str = pb.SerializeToString() |
| 36 | 36 |
| 37 # Write it to disk | 37 # Write it to disk |
| 38 open(opts.outfile, 'w').write(binary_pb_str) | 38 open(opts.outfile, 'wb').write(binary_pb_str) |
| 39 | 39 |
| 40 | 40 |
| 41 def main(): | 41 def main(): |
| 42 parser = optparse.OptionParser() | 42 parser = optparse.OptionParser() |
| 43 # TODO(nparker): Remove this once the bug is fixed. | 43 # TODO(nparker): Remove this once the bug is fixed. |
| 44 parser.add_option('-w', '--wrap', action="store_true", default=False, | 44 parser.add_option('-w', '--wrap', action="store_true", default=False, |
| 45 help='Wrap this script in another python ' | 45 help='Wrap this script in another python ' |
| 46 'execution to disable site-packages. This is a ' | 46 'execution to disable site-packages. This is a ' |
| 47 'fix for http://crbug.com/605592') | 47 'fix for http://crbug.com/605592') |
| 48 parser.add_option('-i', '--infile', | 48 parser.add_option('-i', '--infile', |
| (...skipping 20 matching lines...) Expand all Loading... |
| 69 | 69 |
| 70 try: | 70 try: |
| 71 ConvertProto(opts) | 71 ConvertProto(opts) |
| 72 except Exception as e: | 72 except Exception as e: |
| 73 print "ERROR: %s failed to parse ASCII proto\n%s: %s\n" % ( | 73 print "ERROR: %s failed to parse ASCII proto\n%s: %s\n" % ( |
| 74 sys.argv, opts.infile, str(e)) | 74 sys.argv, opts.infile, str(e)) |
| 75 return 1 | 75 return 1 |
| 76 | 76 |
| 77 if __name__ == '__main__': | 77 if __name__ == '__main__': |
| 78 sys.exit(main()) | 78 sys.exit(main()) |
| OLD | NEW |