Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(58)

Unified Diff: tools/json_schema_compiler/schema_loader.py

Issue 23534063: Make SchemaLoader independent of current working directory. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use two separate paths Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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))
« tools/json_schema_compiler/compiler.py ('K') | « tools/json_schema_compiler/compiler.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698