diff options
author | kalman@chromium.org <kalman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-17 02:11:09 +0000 |
---|---|---|
committer | kalman@chromium.org <kalman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-17 02:11:09 +0000 |
commit | a1f77497010d814003986ed8690b321208eea402 (patch) | |
tree | 3e365566672ab9c5971be51291de13a7aafcd1bd /tools/json_schema_compiler/json_schema.py | |
parent | 18929a9d3aaa97967efa8a93def0c7b818b429be (diff) | |
download | chromium_src-a1f77497010d814003986ed8690b321208eea402.zip chromium_src-a1f77497010d814003986ed8690b321208eea402.tar.gz chromium_src-a1f77497010d814003986ed8690b321208eea402.tar.bz2 |
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
Diffstat (limited to 'tools/json_schema_compiler/json_schema.py')
-rw-r--r-- | tools/json_schema_compiler/json_schema.py | 21 |
1 files changed, 20 insertions, 1 deletions
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 |