Chromium Code Reviews| Index: tools/json_schema_compiler/schema_loader.py |
| diff --git a/tools/json_schema_compiler/schema_loader.py b/tools/json_schema_compiler/schema_loader.py |
| index c434dc167462a26a6e913a28e50d8b9bb79a4126..248e30aa453fa451012b2bdcff2f473ebb876d39 100644 |
| --- a/tools/json_schema_compiler/schema_loader.py |
| +++ b/tools/json_schema_compiler/schema_loader.py |
| @@ -12,7 +12,8 @@ from model import Model |
| class SchemaLoader(object): |
| '''Resolves a type name into the namespace the type belongs to. |
| ''' |
| - def __init__(self, api_path): |
| + def __init__(self, api_path_relative_to_root, api_path): |
|
not at google - send to devlin
2013/09/27 16:10:20
How about: display_path and real_path. Also, add a
msimonides
2013/09/30 07:18:48
Done.
|
| + self._api_path_relative_to_root = api_path_relative_to_root |
| self._api_path = api_path |
| def ResolveType(self, full_name, default_namespace): |
| @@ -25,24 +26,30 @@ class SchemaLoader(object): |
| real_name = None |
| for ext in ['json', 'idl']: |
| filename = '%s.%s' % (namespace_name, ext) |
| - if os.path.exists(filename): |
| + filepath = os.path.join(self._api_path, filename); |
| + if os.path.exists(filepath): |
| real_name = filename |
| break |
| if real_name is None: |
| return None |
| - namespace = Model().AddNamespace(self.LoadSchema(real_name)[0], |
| - os.path.join(self._api_path, real_name)) |
| + namespace = Model().AddNamespace( |
| + self.LoadSchema(real_name)[0], |
| + os.path.join(self._api_path_relative_to_root, real_name)) |
| if type_name not in namespace.types: |
| return None |
| return namespace |
| def LoadSchema(self, schema): |
| + '''Load a schema definition. The schema parameter must be a file name |
| + without any path component - the file is loaded from the path defined by |
| + the api_path argument passed to the constructor.''' |
|
not at google - send to devlin
2013/09/27 16:10:20
Docstring style is
'''Foo
Bar.
'''
not
'''Foo
msimonides
2013/09/30 07:18:48
Done.
|
| schema_filename, schema_extension = os.path.splitext(schema) |
| + schema_path = os.path.join(self._api_path, schema); |
| if schema_extension == '.json': |
| - api_defs = json_schema.Load(schema) |
| + api_defs = json_schema.Load(schema_path) |
| elif schema_extension == '.idl': |
| - api_defs = idl_schema.Load(schema) |
| + api_defs = idl_schema.Load(schema_path) |
| else: |
| sys.exit('Did not recognize file extension %s for schema %s' % |
| (schema_extension, schema)) |