From a1f77497010d814003986ed8690b321208eea402 Mon Sep 17 00:00:00 2001 From: "kalman@chromium.org" Date: Tue, 17 Apr 2012 02:11:09 +0000 Subject: Make json_schema_compiler remove 'nocompile' nodes from JSON at the JSON level rather than at the model level. This gives us automatic nocompile of all properties; previously not all were supported. TEST=tools/json_schema_compiler/json_schema_test.py, unit_tests --gtest_filter=JsonSchemaCompiler* Review URL: http://codereview.chromium.org/10108005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@132514 0039d316-1c4b-4281-b951-d872f2087c98 --- tools/json_schema_compiler/json_schema.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'tools/json_schema_compiler/json_schema.py') diff --git a/tools/json_schema_compiler/json_schema.py b/tools/json_schema_compiler/json_schema.py index 46ca487..240a168 100644 --- a/tools/json_schema_compiler/json_schema.py +++ b/tools/json_schema_compiler/json_schema.py @@ -48,9 +48,28 @@ def StripJSONComments(stream): return result +def DeleteNocompileNodes(item): + def HasNocompile(thing): + return type(thing) == dict and thing.get('nocompile', False) + + if type(item) == dict: + toDelete = [] + for key, value in item.items(): + if HasNocompile(value): + toDelete.append(key) + else: + DeleteNocompileNodes(value) + for key in toDelete: + del item[key] + elif type(item) == list: + item[:] = [DeleteNocompileNodes(thing) + for thing in item if not HasNocompile(thing)] + + return item + def Load(filename): with open(filename, 'r') as handle: - return json.loads(StripJSONComments(handle.read())) + return DeleteNocompileNodes(json.loads(StripJSONComments(handle.read()))) # A dictionary mapping |filename| to the object resulting from loading the JSON -- cgit v1.1