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

Side by Side Diff: chrome/browser/resources/safe_browsing/gen_file_type_proto.py

Issue 1857983002: Add download_file_types.proto with ascii->binary conversion, as a resource. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Tweaks to README.md and proto Created 4 years, 8 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
(Empty)
1 #!/usr/bin/python
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
4 # found in the LICENSE file.
5
6 """
7 Convert the ASCII download_file_types.asciipb proto into a binary resource.
8 """
9
10 import optparse
11 import sys
12
13 import google.protobuf.text_format as text_format
14
15 def ConvertProto(opts):
16
17 # Find the proto code
18 sys.path.append(opts.path)
19 import download_file_types_pb2 as config_pb2
20
21 # Read the ASCII
22 ifile = open(opts.infile, 'r')
23 ascii_pb_str = ifile.read()
24 ifile.close()
25
26 # Parse it into a structure PB
27 pb = config_pb2.DownloadFileTypeConfig()
28 text_format.Merge(ascii_pb_str, pb)
29
30 # Serialize it
31 binary_pb_str = pb.SerializeToString()
32
33 # Write it to disk
34 open(opts.outfile, 'w').write(binary_pb_str)
35
36
37 def main():
38 parser = optparse.OptionParser()
39 parser.add_option('-i', '--infile',
40 help='The ASCII DownloadFileType-proto file to read.')
41 parser.add_option('-o', '--outfile',
42 help='The binary file to write.')
43 parser.add_option('-p', '--path',
44 help='A directory path containing the '+
45 'download_file_types_pb2.py module')
46 (opts, args) = parser.parse_args()
47 if opts.infile is None or opts.outfile is None or opts.path is None:
48 parser.print_help()
49 return 1
50
51 try:
52 ConvertProto(opts)
53 except Exception as e:
54 print "ERROR: %s failed to parse ASCII proto\n%s: %s\n" % (
55 sys.argv[0], opts.infile, str(e))
56 return 1
57
58 if __name__ == '__main__':
59 sys.exit(main())
OLDNEW
« no previous file with comments | « chrome/browser/resources/safe_browsing/download_file_types.asciipb ('k') | chrome/chrome_common.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698