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

Side by Side Diff: CodeGenerator.py

Issue 2482093004: [inspector_protocol] Allow overriding specific config values. (Closed)
Patch Set: typo Created 4 years, 1 month 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
« no previous file with comments | « no previous file | inspector_protocol.gni » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2016 The Chromium Authors. All rights reserved. 1 # Copyright 2016 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 import os.path 5 import os.path
6 import sys 6 import sys
7 import optparse 7 import optparse
8 import collections 8 import collections
9 import functools 9 import functools
10 try: 10 try:
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 if optional_key.find(".") == -1 and optional_key not in keys: 45 if optional_key.find(".") == -1 and optional_key not in keys:
46 keys.append(optional_key) 46 keys.append(optional_key)
47 values.append(defaults[optional]) 47 values.append(defaults[optional])
48 return collections.namedtuple('X', keys)(*values) 48 return collections.namedtuple('X', keys)(*values)
49 49
50 try: 50 try:
51 cmdline_parser = optparse.OptionParser() 51 cmdline_parser = optparse.OptionParser()
52 cmdline_parser.add_option("--output_base") 52 cmdline_parser.add_option("--output_base")
53 cmdline_parser.add_option("--jinja_dir") 53 cmdline_parser.add_option("--jinja_dir")
54 cmdline_parser.add_option("--config") 54 cmdline_parser.add_option("--config")
55 cmdline_parser.add_option("--config_value", action="append", type="strin g")
55 arg_options, _ = cmdline_parser.parse_args() 56 arg_options, _ = cmdline_parser.parse_args()
56 jinja_dir = arg_options.jinja_dir 57 jinja_dir = arg_options.jinja_dir
57 if not jinja_dir: 58 if not jinja_dir:
58 raise Exception("jinja directory must be specified") 59 raise Exception("jinja directory must be specified")
59 output_base = arg_options.output_base 60 output_base = arg_options.output_base
60 if not output_base: 61 if not output_base:
61 raise Exception("Base output directory must be specified") 62 raise Exception("Base output directory must be specified")
62 config_file = arg_options.config 63 config_file = arg_options.config
63 if not config_file: 64 if not config_file:
64 raise Exception("Config file name must be specified") 65 raise Exception("Config file name must be specified")
65 config_base = os.path.dirname(config_file) 66 config_base = os.path.dirname(config_file)
67 config_values = arg_options.config_value
66 except Exception: 68 except Exception:
67 # Work with python 2 and 3 http://docs.python.org/py3k/howto/pyporting.h tml 69 # Work with python 2 and 3 http://docs.python.org/py3k/howto/pyporting.h tml
68 exc = sys.exc_info()[1] 70 exc = sys.exc_info()[1]
69 sys.stderr.write("Failed to parse command-line arguments: %s\n\n" % exc) 71 sys.stderr.write("Failed to parse command-line arguments: %s\n\n" % exc)
70 exit(1) 72 exit(1)
71 73
72 try: 74 try:
73 config_json_file = open(config_file, "r") 75 config_json_file = open(config_file, "r")
74 config_json_string = config_json_file.read() 76 config_json_string = config_json_file.read()
75 config_partial = json_to_object(config_json_string, output_base, config_ base) 77 config_partial = json_to_object(config_json_string, output_base, config_ base)
76 config_json_file.close() 78 config_json_file.close()
77 defaults = { 79 defaults = {
78 ".imported": False, 80 ".imported": False,
79 ".imported.export_macro": "", 81 ".imported.export_macro": "",
80 ".imported.export_header": False, 82 ".imported.export_header": False,
81 ".imported.header": False, 83 ".imported.header": False,
82 ".imported.package": False, 84 ".imported.package": False,
83 ".protocol.export_macro": "", 85 ".protocol.export_macro": "",
84 ".protocol.export_header": False, 86 ".protocol.export_header": False,
85 ".protocol.options": False, 87 ".protocol.options": False,
86 ".exported": False, 88 ".exported": False,
87 ".exported.export_macro": "", 89 ".exported.export_macro": "",
88 ".exported.export_header": False, 90 ".exported.export_header": False,
89 ".lib": False, 91 ".lib": False,
90 ".lib.export_macro": "", 92 ".lib.export_macro": "",
91 ".lib.export_header": False, 93 ".lib.export_header": False,
92 } 94 }
95 for key_value in config_values:
96 parts = key_value.split("=")
97 if len(parts) == 2:
98 defaults["." + parts[0]] = parts[1]
93 return (jinja_dir, config_file, init_defaults(config_partial, "", defaul ts)) 99 return (jinja_dir, config_file, init_defaults(config_partial, "", defaul ts))
94 except Exception: 100 except Exception:
95 # Work with python 2 and 3 http://docs.python.org/py3k/howto/pyporting.h tml 101 # Work with python 2 and 3 http://docs.python.org/py3k/howto/pyporting.h tml
96 exc = sys.exc_info()[1] 102 exc = sys.exc_info()[1]
97 sys.stderr.write("Failed to parse config file: %s\n\n" % exc) 103 sys.stderr.write("Failed to parse config file: %s\n\n" % exc)
98 exit(1) 104 exit(1)
99 105
100 106
101 def to_title_case(name): 107 def to_title_case(name):
102 return name[:1].upper() + name[1:] 108 return name[:1].upper() + name[1:]
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after
534 if up_to_date: 540 if up_to_date:
535 sys.exit() 541 sys.exit()
536 542
537 for file_name, content in outputs.iteritems(): 543 for file_name, content in outputs.iteritems():
538 out_file = open(file_name, "w") 544 out_file = open(file_name, "w")
539 out_file.write(content) 545 out_file.write(content)
540 out_file.close() 546 out_file.close()
541 547
542 548
543 main() 549 main()
OLDNEW
« no previous file with comments | « no previous file | inspector_protocol.gni » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698