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

Unified 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 side-by-side diff with in-line comments
Download patch
« 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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/resources/safe_browsing/gen_file_type_proto.py
diff --git a/chrome/browser/resources/safe_browsing/gen_file_type_proto.py b/chrome/browser/resources/safe_browsing/gen_file_type_proto.py
new file mode 100755
index 0000000000000000000000000000000000000000..cbdaa3bd3a6b13a90723d8479bd19dd1c1885f4b
--- /dev/null
+++ b/chrome/browser/resources/safe_browsing/gen_file_type_proto.py
@@ -0,0 +1,59 @@
+#!/usr/bin/python
+# Copyright 2016 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+"""
+ Convert the ASCII download_file_types.asciipb proto into a binary resource.
+"""
+
+import optparse
+import sys
+
+import google.protobuf.text_format as text_format
+
+def ConvertProto(opts):
+
+ # Find the proto code
+ sys.path.append(opts.path)
+ import download_file_types_pb2 as config_pb2
+
+ # Read the ASCII
+ ifile = open(opts.infile, 'r')
+ ascii_pb_str = ifile.read()
+ ifile.close()
+
+ # Parse it into a structure PB
+ pb = config_pb2.DownloadFileTypeConfig()
+ text_format.Merge(ascii_pb_str, pb)
+
+ # Serialize it
+ binary_pb_str = pb.SerializeToString()
+
+ # Write it to disk
+ open(opts.outfile, 'w').write(binary_pb_str)
+
+
+def main():
+ parser = optparse.OptionParser()
+ parser.add_option('-i', '--infile',
+ help='The ASCII DownloadFileType-proto file to read.')
+ parser.add_option('-o', '--outfile',
+ help='The binary file to write.')
+ parser.add_option('-p', '--path',
+ help='A directory path containing the '+
+ 'download_file_types_pb2.py module')
+ (opts, args) = parser.parse_args()
+ if opts.infile is None or opts.outfile is None or opts.path is None:
+ parser.print_help()
+ return 1
+
+ try:
+ ConvertProto(opts)
+ except Exception as e:
+ print "ERROR: %s failed to parse ASCII proto\n%s: %s\n" % (
+ sys.argv[0], opts.infile, str(e))
+ return 1
+
+if __name__ == '__main__':
+ sys.exit(main())
« 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