summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorcduvall@chromium.org <cduvall@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-02 16:09:16 +0000
committercduvall@chromium.org <cduvall@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-02 16:09:16 +0000
commitf656805bcc1e3996d3f6fccaa385ea2438d70003 (patch)
tree1eed90b43d01b712368ef3ff79f4d329fedd2c65 /tools
parent9cfbf66521b2c1151d660a5b82f5183204663e5e (diff)
downloadchromium_src-f656805bcc1e3996d3f6fccaa385ea2438d70003.zip
chromium_src-f656805bcc1e3996d3f6fccaa385ea2438d70003.tar.gz
chromium_src-f656805bcc1e3996d3f6fccaa385ea2438d70003.tar.bz2
Allow comments in extension config files.
Added a script to remove comments from the extension api JSON files before processing for the extension docs. We will now be able to comment in the JSON files, and they should be much easier to read. Also added the license header to all the JSON files. BUG=114233 TEST=Put comments in one of the JSON files and remake the docs. They will make with no problems. Review URL: http://codereview.chromium.org/9447090 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@124660 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'tools')
-rw-r--r--tools/json_schema_compiler/compiler.py8
-rw-r--r--tools/json_schema_compiler/cpp_type_generator_test.py8
-rw-r--r--tools/json_schema_compiler/json_schema.py19
-rw-r--r--tools/json_schema_compiler/model_test.py8
-rwxr-xr-xtools/json_schema_compiler/previewserver.py8
5 files changed, 33 insertions, 18 deletions
diff --git a/tools/json_schema_compiler/compiler.py b/tools/json_schema_compiler/compiler.py
index 54ab62f..fb84a6c 100644
--- a/tools/json_schema_compiler/compiler.py
+++ b/tools/json_schema_compiler/compiler.py
@@ -19,7 +19,7 @@ Usage example:
import cc_generator
import cpp_type_generator
import h_generator
-import json
+from json_schema import LoadJSON
import model
import optparse
import os.path
@@ -49,8 +49,7 @@ if __name__ == '__main__':
# Actually generate for source file.
- with open(schema, 'r') as schema_file:
- api_defs = json.loads(schema_file.read())
+ api_defs = LoadJSON(schema)
for target_namespace in api_defs:
referenced_schemas = target_namespace.get('dependencies', [])
@@ -58,8 +57,7 @@ if __name__ == '__main__':
for referenced_schema in referenced_schemas:
referenced_schema_path = os.path.join(
os.path.dirname(schema), referenced_schema + '.json')
- with open(referenced_schema_path, 'r') as referenced_schema_file:
- referenced_api_defs = json.loads(referenced_schema_file.read())
+ referenced_api_defs = LoadJSON(referenced_schema_path)
for namespace in referenced_api_defs:
api_model.AddNamespace(namespace,
diff --git a/tools/json_schema_compiler/cpp_type_generator_test.py b/tools/json_schema_compiler/cpp_type_generator_test.py
index ac16262..e58dbac 100644
--- a/tools/json_schema_compiler/cpp_type_generator_test.py
+++ b/tools/json_schema_compiler/cpp_type_generator_test.py
@@ -3,22 +3,22 @@
# found in the LICENSE file.
from cpp_type_generator import CppTypeGenerator
-import json
+from json_schema import LoadJSON
import model
import unittest
class CppTypeGeneratorTest(unittest.TestCase):
def setUp(self):
self.model = model.Model()
- self.permissions_json = json.loads(open('test/permissions.json').read())
+ self.permissions_json = LoadJSON('test/permissions.json')
self.model.AddNamespace(self.permissions_json[0],
'path/to/permissions.json')
self.permissions = self.model.namespaces.get('permissions')
- self.windows_json = json.loads(open('test/windows.json').read())
+ self.windows_json = LoadJSON('test/windows.json')
self.model.AddNamespace(self.windows_json[0],
'path/to/window.json')
self.windows = self.model.namespaces.get('windows')
- self.tabs_json = json.loads(open('test/tabs.json').read())
+ self.tabs_json = LoadJSON('test/tabs.json')
self.model.AddNamespace(self.tabs_json[0],
'path/to/tabs.json')
self.tabs = self.model.namespaces.get('tabs')
diff --git a/tools/json_schema_compiler/json_schema.py b/tools/json_schema_compiler/json_schema.py
new file mode 100644
index 0000000..aa192c0
--- /dev/null
+++ b/tools/json_schema_compiler/json_schema.py
@@ -0,0 +1,19 @@
+# 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 json
+import os.path
+import sys
+
+# We need to get json_minify from the third_party directory.
+# This is similar to what is done in chrome/common/extensions/docs/build.py
+third_party_path = os.path.join(os.path.dirname(os.path.realpath(__file__)),
+ os.pardir, os.pardir, 'third_party/')
+if third_party_path not in sys.path:
+ sys.path.insert(0, third_party_path)
+import json_minify as minify
+
+def LoadJSON(filename):
+ with open(filename, 'r') as handle:
+ return json.loads(minify.json_minify(handle.read()))
diff --git a/tools/json_schema_compiler/model_test.py b/tools/json_schema_compiler/model_test.py
index 3217498..a588968 100644
--- a/tools/json_schema_compiler/model_test.py
+++ b/tools/json_schema_compiler/model_test.py
@@ -2,22 +2,22 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
-import json
+from json_schema import LoadJSON
import model
import unittest
class ModelTest(unittest.TestCase):
def setUp(self):
self.model = model.Model()
- self.permissions_json = json.loads(open('test/permissions.json').read())
+ self.permissions_json = LoadJSON('test/permissions.json')
self.model.AddNamespace(self.permissions_json[0],
'path/to/permissions.json')
self.permissions = self.model.namespaces.get('permissions')
- self.windows_json = json.loads(open('test/windows.json').read())
+ self.windows_json = LoadJSON('test/windows.json')
self.model.AddNamespace(self.windows_json[0],
'path/to/window.json')
self.windows = self.model.namespaces.get('windows')
- self.tabs_json = json.loads(open('test/tabs.json').read())
+ self.tabs_json = LoadJSON('test/tabs.json')
self.model.AddNamespace(self.tabs_json[0],
'path/to/tabs.json')
self.tabs = self.model.namespaces.get('tabs')
diff --git a/tools/json_schema_compiler/previewserver.py b/tools/json_schema_compiler/previewserver.py
index 384171e..8a6f6ab 100755
--- a/tools/json_schema_compiler/previewserver.py
+++ b/tools/json_schema_compiler/previewserver.py
@@ -11,7 +11,7 @@ import code
import cpp_type_generator
import cpp_util
import h_generator
-import json
+from json_schema import LoadJSON
import model
import optparse
import os
@@ -188,8 +188,7 @@ updateEverything();
try:
# Get main json file
- with open(json_file_path) as json_file:
- api_defs = json.loads(json_file.read())
+ api_defs = LoadJSON(json_file_path)
namespace = api_model.AddNamespace(api_defs[0], json_file_path)
if not namespace:
body.Append("<pre>Target file %s is marked nocompile</pre>" %
@@ -201,8 +200,7 @@ updateEverything();
# Get json file depedencies
for dependency in api_defs[0].get('dependencies', []):
json_file_path = os.path.join(filedir, dependency + '.json')
- with open(json_file_path) as json_file:
- api_defs = json.loads(json_file.read())
+ api_defs = LoadJSON(json_file_path)
referenced_namespace = api_model.AddNamespace(api_defs[0],
json_file_path)
if referenced_namespace: