| 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 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 | 90 |
| 91 | 91 |
| 92 class Json5File(object): | 92 class Json5File(object): |
| 93 def __init__(self, doc, default_metadata=None): | 93 def __init__(self, doc, default_metadata=None): |
| 94 self.name_dictionaries = [] | 94 self.name_dictionaries = [] |
| 95 self.metadata = copy.deepcopy(default_metadata if default_metadata else
{}) | 95 self.metadata = copy.deepcopy(default_metadata if default_metadata else
{}) |
| 96 self._defaults = {} | 96 self._defaults = {} |
| 97 self._process(doc) | 97 self._process(doc) |
| 98 | 98 |
| 99 @classmethod | 99 @classmethod |
| 100 def load_from_files(cls, file_paths, default_metadata): | 100 def load_from_files(cls, file_paths, default_metadata=None): |
| 101 merged_doc = dict() | 101 merged_doc = dict() |
| 102 for path in file_paths: | 102 for path in file_paths: |
| 103 assert path.endswith(".json5") | 103 assert path.endswith(".json5") |
| 104 with open(os.path.abspath(path)) as json5_file: | 104 with open(os.path.abspath(path)) as json5_file: |
| 105 doc = _json5_load(json5_file.read()) | 105 doc = _json5_load(json5_file.read()) |
| 106 if not merged_doc: | 106 if not merged_doc: |
| 107 merged_doc = doc | 107 merged_doc = doc |
| 108 else: | 108 else: |
| 109 _merge_doc(merged_doc, doc) | 109 _merge_doc(merged_doc, doc) |
| 110 return Json5File(merged_doc, default_metadata) | 110 return Json5File(merged_doc, default_metadata) |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 parser.add_argument("--developer_dir", help="Path to Xcode.") | 224 parser.add_argument("--developer_dir", help="Path to Xcode.") |
| 225 parser.add_argument("--output_dir", default=os.getcwd()) | 225 parser.add_argument("--output_dir", default=os.getcwd()) |
| 226 args = parser.parse_args() | 226 args = parser.parse_args() |
| 227 | 227 |
| 228 if args.developer_dir: | 228 if args.developer_dir: |
| 229 os.environ["DEVELOPER_DIR"] = args.developer_dir | 229 os.environ["DEVELOPER_DIR"] = args.developer_dir |
| 230 | 230 |
| 231 writer = self._writer_class(args.files) | 231 writer = self._writer_class(args.files) |
| 232 writer.set_gperf_path(args.gperf) | 232 writer.set_gperf_path(args.gperf) |
| 233 writer.write_files(args.output_dir) | 233 writer.write_files(args.output_dir) |
| OLD | NEW |