| 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..80f1d3f27cea51dc5b44a0e6bce36f4cd8ad3494 100644
|
| --- a/tools/json_schema_compiler/schema_loader.py
|
| +++ b/tools/json_schema_compiler/schema_loader.py
|
| @@ -11,9 +11,16 @@ from model import Model
|
|
|
| class SchemaLoader(object):
|
| '''Resolves a type name into the namespace the type belongs to.
|
| +
|
| + Properties:
|
| + - |display_path| path to the directory with the API header files, intended for
|
| + use with the Model.
|
| + - |real_path| path to the directory with the API header files, used for file
|
| + access.
|
| '''
|
| - def __init__(self, api_path):
|
| - self._api_path = api_path
|
| + def __init__(self, display_path, real_path):
|
| + self._display_path = display_path
|
| + self._real_path = real_path
|
|
|
| def ResolveType(self, full_name, default_namespace):
|
| name_parts = full_name.rsplit('.', 1)
|
| @@ -25,24 +32,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._real_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._display_path, 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 real_path argument passed to the constructor.'''
|
| schema_filename, schema_extension = os.path.splitext(schema)
|
|
|
| + schema_path = os.path.join(self._real_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))
|
|
|