| OLD | NEW |
| 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 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 else: | 145 else: |
| 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 if not self.parameters: | |
| 156 entry.update(item) | |
| 157 return entry | |
| 158 entry["name"] = item.pop("name") | 155 entry["name"] = item.pop("name") |
| 159 # Validate parameters if it's specified. | |
| 160 for key, value in item.items(): | 156 for key, value in item.items(): |
| 161 if key not in self.parameters: | 157 if key not in self.parameters: |
| 162 raise Exception( | 158 raise Exception( |
| 163 "Unknown parameter: '%s'\nKnown params: %s" % | 159 "Unknown parameter: '%s'\nKnown params: %s" % |
| 164 (key, self.parameters.keys())) | 160 (key, self.parameters.keys())) |
| 165 if self.parameters[key]: | 161 if self.parameters[key]: |
| 166 self._validate_parameter(self.parameters[key], value) | 162 self._validate_parameter(self.parameters[key], value) |
| 167 entry[key] = value | 163 entry[key] = value |
| 168 return entry | 164 return entry |
| 169 | 165 |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 parser.add_argument("--developer_dir", help="Path to Xcode.") | 237 parser.add_argument("--developer_dir", help="Path to Xcode.") |
| 242 parser.add_argument("--output_dir", default=os.getcwd()) | 238 parser.add_argument("--output_dir", default=os.getcwd()) |
| 243 args = parser.parse_args() | 239 args = parser.parse_args() |
| 244 | 240 |
| 245 if args.developer_dir: | 241 if args.developer_dir: |
| 246 os.environ["DEVELOPER_DIR"] = args.developer_dir | 242 os.environ["DEVELOPER_DIR"] = args.developer_dir |
| 247 | 243 |
| 248 writer = self._writer_class(args.files) | 244 writer = self._writer_class(args.files) |
| 249 writer.set_gperf_path(args.gperf) | 245 writer.set_gperf_path(args.gperf) |
| 250 writer.write_files(args.output_dir) | 246 writer.write_files(args.output_dir) |
| OLD | NEW |