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

Unified Diff: tools/json_schema_compiler/json_schema.py

Issue 10108005: Make json_schema_compiler remove 'nocompile' nodes from JSON at the JSON level (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: yoz Created 8 years, 8 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
« no previous file with comments | « no previous file | tools/json_schema_compiler/json_schema_test.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: 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 46ca4874c57486e55dcebfd00eed29ed393b0726..240a1685f70db8a7319f0e2520e8ff40f66a8b39 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
« no previous file with comments | « no previous file | tools/json_schema_compiler/json_schema_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698