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

Side by Side Diff: third_party/WebKit/Source/build/scripts/json5_generator.py

Issue 2645283006: Convert make_qualified_names and make_element_factory to use JSON5. (Closed)
Patch Set: Fix parameters skip Created 3 years, 10 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
1 # Copyright (c) 2017 The Chromium Authors. All rights reserved. 1 # Copyright (c) 2017 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 """Generic generator for configuration files in JSON5 format. 5 """Generic generator for configuration files in JSON5 format.
6 6
7 The configuration file is expected to contain either a data array or a data map, 7 The configuration file is expected to contain either a data array or a data map,
8 an optional parameters validation map, and an optional metdata map. Examples: 8 an optional parameters validation map, and an optional metdata map. Examples:
9 { 9 {
10 data: [ 10 data: [
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 self._defaults[key] = None 146 self._defaults[key] = None
147 147
148 def _get_entry(self, item): 148 def _get_entry(self, item):
149 entry = copy.deepcopy(self._defaults) 149 entry = copy.deepcopy(self._defaults)
150 if type(item) is not dict: 150 if type(item) is not dict:
151 entry["name"] = item 151 entry["name"] = item
152 return entry 152 return entry
153 if "name" not in item: 153 if "name" not in item:
154 raise Exception("Missing name in item: %s" % item) 154 raise Exception("Missing name in item: %s" % item)
155 entry["name"] = item.pop("name") 155 entry["name"] = item.pop("name")
156 # Valid parameters if it's specified.
156 for key, value in item.items(): 157 for key, value in item.items():
158 entry[key] = value
sashab 2017/01/31 23:09:19 Why did you move this up here?
ktyliu 2017/01/31 23:42:06 I am doing a "continue" below (for the case where
159 if not self.parameters:
160 continue
157 if key not in self.parameters: 161 if key not in self.parameters:
158 raise Exception( 162 raise Exception(
159 "Unknown parameter: '%s'\nKnown params: %s" % 163 "Unknown parameter: '%s'\nKnown params: %s" %
160 (key, self.parameters.keys())) 164 (key, self.parameters.keys()))
161 if self.parameters[key]: 165 if self.parameters[key]:
162 self._validate_parameter(self.parameters[key], value) 166 self._validate_parameter(self.parameters[key], value)
163 entry[key] = value
164 return entry 167 return entry
165 168
166 def _validate_parameter(self, parameter, value): 169 def _validate_parameter(self, parameter, value):
167 valid_values = parameter.get("valid_values") 170 valid_values = parameter.get("valid_values")
168 if valid_values and value not in valid_values: 171 if valid_values and value not in valid_values:
169 raise Exception("Unknown value: '%s'\nKnown values: %s" % 172 raise Exception("Unknown value: '%s'\nKnown values: %s" %
170 (value, valid_values)) 173 (value, valid_values))
171 valid_type = parameter.get("valid_type") 174 valid_type = parameter.get("valid_type")
172 if valid_type and type(value).__name__ != valid_type: 175 if valid_type and type(value).__name__ != valid_type:
173 raise Exception("Incorrect type: '%s'\nExpected type: %s" % 176 raise Exception("Incorrect type: '%s'\nExpected type: %s" %
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 parser.add_argument("--developer_dir", help="Path to Xcode.") 231 parser.add_argument("--developer_dir", help="Path to Xcode.")
229 parser.add_argument("--output_dir", default=os.getcwd()) 232 parser.add_argument("--output_dir", default=os.getcwd())
230 args = parser.parse_args() 233 args = parser.parse_args()
231 234
232 if args.developer_dir: 235 if args.developer_dir:
233 os.environ["DEVELOPER_DIR"] = args.developer_dir 236 os.environ["DEVELOPER_DIR"] = args.developer_dir
234 237
235 writer = self._writer_class(args.files) 238 writer = self._writer_class(args.files)
236 writer.set_gperf_path(args.gperf) 239 writer.set_gperf_path(args.gperf)
237 writer.write_files(args.output_dir) 240 writer.write_files(args.output_dir)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698