
The SchemaLoader name implies that the object is used for loading schemas, but for some reason also has logic to resolve a type and namespace. Move this into a separate NamespaceResolver file to make it easier to reuse SchemaLoader. BUG=None Review-Url: https://codereview.chromium.org/2596583002 Cr-Commit-Position: refs/heads/master@{#440201}
34 lines
1.0 KiB
Python
34 lines
1.0 KiB
Python
# Copyright (c) 2012 The Chromium Authors. All rights reserved.
|
|
# Use of this source code is governed by a BSD-style license that can be
|
|
# found in the LICENSE file.
|
|
|
|
import os
|
|
import sys
|
|
|
|
import idl_schema
|
|
import json_schema
|
|
|
|
class SchemaLoader(object):
|
|
'''Loads a schema from a provided filename.
|
|
|root|: path to the root directory.
|
|
'''
|
|
def __init__(self, root):
|
|
self._root = root
|
|
|
|
def LoadSchema(self, schema):
|
|
'''Load a schema definition. The schema parameter must be a file name
|
|
with the full path relative to the root.'''
|
|
_, schema_extension = os.path.splitext(schema)
|
|
|
|
schema_path = os.path.join(self._root, schema)
|
|
if schema_extension == '.json':
|
|
api_defs = json_schema.Load(schema_path)
|
|
elif schema_extension == '.idl':
|
|
api_defs = idl_schema.Load(schema_path)
|
|
else:
|
|
sys.exit('Did not recognize file extension %s for schema %s' %
|
|
(schema_extension, schema))
|
|
|
|
# TODO(devlin): This returns a list. Does it need to? Is it ever > 1?
|
|
return api_defs
|