diff options
Diffstat (limited to 'chromium/tools/json_schema_compiler/schema_loader.py')
-rw-r--r-- | chromium/tools/json_schema_compiler/schema_loader.py | 30 |
1 files changed, 20 insertions, 10 deletions
diff --git a/chromium/tools/json_schema_compiler/schema_loader.py b/chromium/tools/json_schema_compiler/schema_loader.py index c434dc16746..9fea1ab8250 100644 --- a/chromium/tools/json_schema_compiler/schema_loader.py +++ b/chromium/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,29 +32,32 @@ 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)) - if len(api_defs) != 1: - sys.exit('File %s has multiple schemas. Files are only allowed to contain' - 'a single schema.' % schema) return api_defs |