Index: third_party/WebKit/Source/devtools/scripts/generate_protocol_externs.py |
diff --git a/third_party/WebKit/Source/devtools/scripts/generate_protocol_externs.py b/third_party/WebKit/Source/devtools/scripts/generate_protocol_externs.py |
index fca2d6333f24a6ed1ecd3cacae55ec858e2bdabb..b7a95394061d1ccb127701ecda76d12518556a20 100755 |
--- a/third_party/WebKit/Source/devtools/scripts/generate_protocol_externs.py |
+++ b/third_party/WebKit/Source/devtools/scripts/generate_protocol_externs.py |
@@ -27,7 +27,12 @@ |
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
+import os |
import re |
+try: |
+ import json |
+except ImportError: |
+ import simplejson as json |
type_traits = { |
"any": "*", |
@@ -88,13 +93,26 @@ def param_type(domain_name, param): |
return "!! Type not found: " + type_id |
-def generate_protocol_externs(output_path, input_path): |
- input_file = open(input_path, "r") |
+def load_domain(file, domains): |
+ if not os.path.isfile(file): |
+ return |
+ input_file = open(file, "r") |
json_string = input_file.read() |
- json_string = json_string.replace(": true", ": True") |
- json_string = json_string.replace(": false", ": False") |
- json_api = eval(json_string)["domains"] |
+ parsed_json = json.loads(json_string) |
+ domains.append(parsed_json) |
+ |
+def load_domains(folder, domains): |
+ for f in os.listdir(folder): |
+ filename = os.path.join(folder, f) |
+ if filename.endswith(".json") and os.path.isfile(filename): |
+ load_domain(filename, domains) |
+ |
+ |
+def generate_protocol_externs(output_path, folder1, folder2): |
+ domains = [] |
+ load_domains(folder1, domains) |
+ load_domains(folder2, domains) |
output_file = open(output_path, "w") |
output_file.write( |
@@ -106,14 +124,14 @@ var Protocol = {}; |
Protocol.Error; |
""") |
- for domain in json_api: |
+ for domain in domains: |
domain_name = domain["domain"] |
if "types" in domain: |
for type in domain["types"]: |
type_id = full_qualified_type_id(domain_name, type["id"]) |
ref_types[type_id] = "%sAgent.%s" % (domain_name, type["id"]) |
- for domain in json_api: |
+ for domain in domains: |
domain_name = domain["domain"] |
promisified = domain_name in promisified_domains |
@@ -210,7 +228,7 @@ Protocol.Error; |
output_file.write("Protocol.Agents = function(agentsMap){this._agentsMap;};\n") |
output_file.write("/**\n * @param {string} domain\n * @param {!Object} dispatcher\n */\n") |
output_file.write("Protocol.Agents.prototype.registerDispatcher = function(domain, dispatcher){};\n") |
- for domain in json_api: |
+ for domain in domains: |
domain_name = domain["domain"] |
uppercase_length = 0 |
while uppercase_length < len(domain_name) and domain_name[uppercase_length].isupper(): |