Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 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 | 5 import os |
| 6 import sys | 6 import sys |
| 7 | 7 |
| 8 import idl_schema | 8 import idl_schema |
| 9 import json_schema | 9 import json_schema |
| 10 from model import Model | 10 from model import Model |
| 11 | 11 |
| 12 class SchemaLoader(object): | 12 class SchemaLoader(object): |
| 13 '''Resolves a type name into the namespace the type belongs to. | 13 '''Resolves a type name into the namespace the type belongs to. |
| 14 ''' | 14 ''' |
| 15 def __init__(self, api_path): | 15 def __init__(self, api_path, multiple_schemas=False): |
| 16 self._api_path = api_path | 16 self._api_path = api_path |
| 17 self._multiple_schemas = multiple_schemas | |
| 17 | 18 |
| 18 def ResolveType(self, full_name, default_namespace): | 19 def ResolveType(self, full_name, default_namespace): |
| 19 name_parts = full_name.rsplit('.', 1) | 20 name_parts = full_name.rsplit('.', 1) |
| 20 if len(name_parts) == 1: | 21 if len(name_parts) == 1: |
| 21 if full_name not in default_namespace.types: | 22 if full_name not in default_namespace.types: |
| 22 return None | 23 return None |
| 23 return default_namespace | 24 return default_namespace |
| 24 namespace_name, type_name = name_parts | 25 namespace_name, type_name = name_parts |
| 25 real_name = None | 26 real_name = None |
| 26 for ext in ['json', 'idl']: | 27 for ext in ['json', 'idl']: |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 39 def LoadSchema(self, schema): | 40 def LoadSchema(self, schema): |
| 40 schema_filename, schema_extension = os.path.splitext(schema) | 41 schema_filename, schema_extension = os.path.splitext(schema) |
| 41 | 42 |
| 42 if schema_extension == '.json': | 43 if schema_extension == '.json': |
| 43 api_defs = json_schema.Load(schema) | 44 api_defs = json_schema.Load(schema) |
| 44 elif schema_extension == '.idl': | 45 elif schema_extension == '.idl': |
| 45 api_defs = idl_schema.Load(schema) | 46 api_defs = idl_schema.Load(schema) |
| 46 else: | 47 else: |
| 47 sys.exit('Did not recognize file extension %s for schema %s' % | 48 sys.exit('Did not recognize file extension %s for schema %s' % |
| 48 (schema_extension, schema)) | 49 (schema_extension, schema)) |
| 49 if len(api_defs) != 1: | 50 if len(api_defs) != 1 and not self._multiple_schemas: |
| 50 sys.exit('File %s has multiple schemas. Files are only allowed to contain' | 51 sys.exit('File %s has multiple schemas. Files are only allowed to contain' |
| 51 'a single schema.' % schema) | 52 'a single schema.' % schema) |
|
not at google - send to devlin
2013/09/13 21:37:52
meh, just kill this check and don't pass in that b
dhnishi (use Chromium)
2013/09/16 22:26:21
Done.
| |
| 52 | 53 |
| 53 return api_defs | 54 return api_defs |
| OLD | NEW |