Commit 5995a85e authored by Raul Tambre's avatar Raul Tambre Committed by Commit Bot

Support Python 3 in //components/domain_reliability/bake_in_configs.py

The script still works with Python 2.
There are no intended behaviour changes.

Bug: 941669
Change-Id: I9d0d56b95eccc82da7820347877f4df0339ff731
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1556773
Auto-Submit: Raul Tambre <raul@tambre.ee>
Commit-Queue: Asanka Herath <asanka@chromium.org>
Reviewed-by: default avatarAsanka Herath <asanka@chromium.org>
Cr-Commit-Position: refs/heads/master@{#648721}
parent 99075a00
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
encodes their contents as an array of C strings that gets compiled in to Chrome encodes their contents as an array of C strings that gets compiled in to Chrome
and loaded at runtime.""" and loaded at runtime."""
from __future__ import print_function
import ast import ast
import json import json
...@@ -532,13 +533,13 @@ def main(): ...@@ -532,13 +533,13 @@ def main():
opts, args = parser.parse_args() opts, args = parser.parse_args()
if not opts.output: if not opts.output:
print >> sys.stderr, "--output argument required" print("--output argument required", file=sys.stderr)
return 1 return 1
if opts.gypi_file: if opts.gypi_file:
# .gypi-style input. # .gypi-style input.
if not opts.gypi_relative_to: if not opts.gypi_relative_to:
print >> sys.stderr, "--gypi-relative-to is required with --gypi-file" print("--gypi-relative-to is required with --gypi-file", file=sys.stderr)
return 1 return 1
json_files = read_json_files_from_gypi(opts.gypi_file) json_files = read_json_files_from_gypi(opts.gypi_file)
json_files = [ os.path.join(opts.gypi_relative_to, f) for f in json_files ] json_files = [ os.path.join(opts.gypi_relative_to, f) for f in json_files ]
...@@ -547,7 +548,7 @@ def main(): ...@@ -547,7 +548,7 @@ def main():
# Regular file list input. # Regular file list input.
json_files = read_json_files_from_file(opts.file_list) json_files = read_json_files_from_file(opts.file_list)
else: else:
print >> sys.stderr, "Either --file-list or --gypi-file is required." print("Either --file-list or --gypi-file is required.", file=sys.stderr)
return 1 return 1
cpp_code = CC_HEADER cpp_code = CC_HEADER
...@@ -558,18 +559,19 @@ def main(): ...@@ -558,18 +559,19 @@ def main():
json_text = f.read() json_text = f.read()
try: try:
config = json.loads(json_text) config = json.loads(json_text)
except ValueError, e: except ValueError as e:
print >> sys.stderr, "%s: error parsing JSON: %s" % (json_file, e) print("%s: error parsing JSON: %s" % (json_file, e), file=sys.stderr)
found_invalid_config = True found_invalid_config = True
continue continue
if 'origin' not in config: if 'origin' not in config:
print >> sys.stderr, '%s: no origin found' % json_file print('%s: no origin found' % json_file, file=sys.stderr)
found_invalid_config = True found_invalid_config = True
continue continue
origin = config['origin'] origin = config['origin']
if not origin_is_whitelisted(origin): if not origin_is_whitelisted(origin):
print >> sys.stderr, ('%s: origin "%s" not in whitelist' % print(
(json_file, origin)) '%s: origin "%s" not in whitelist' % (json_file, origin),
file=sys.stderr)
found_invalid_config = True found_invalid_config = True
continue continue
...@@ -585,7 +587,7 @@ def main(): ...@@ -585,7 +587,7 @@ def main():
if found_invalid_config: if found_invalid_config:
return 1 return 1
with open(opts.output, 'wb') as f: with open(opts.output, 'w') as f:
f.write(cpp_code) f.write(cpp_code)
return 0 return 0
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment