|
|
@ -14,6 +14,7 @@ import json
|
|
|
|
import os
|
|
|
|
import os
|
|
|
|
import re
|
|
|
|
import re
|
|
|
|
import subprocess
|
|
|
|
import subprocess
|
|
|
|
|
|
|
|
import sys
|
|
|
|
import urllib
|
|
|
|
import urllib
|
|
|
|
import yaml
|
|
|
|
import yaml
|
|
|
|
|
|
|
|
|
|
|
@ -153,21 +154,42 @@ def get_json_schema_object_fields(obj, enforce_title=False,
|
|
|
|
|
|
|
|
|
|
|
|
required_keys = set(obj.get("required", []))
|
|
|
|
required_keys = set(obj.get("required", []))
|
|
|
|
|
|
|
|
|
|
|
|
fields = {
|
|
|
|
obj_title = obj.get("title")
|
|
|
|
"title": obj.get("title"),
|
|
|
|
first_table_rows = []
|
|
|
|
"rows": []
|
|
|
|
tables = []
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tables = [fields]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for key_name in props:
|
|
|
|
for key_name in props:
|
|
|
|
logger.debug("Processing property %s.%s", obj.get('title'), key_name)
|
|
|
|
try:
|
|
|
|
prop = inherit_parents(props[key_name])
|
|
|
|
logger.debug("Processing property %s.%s", obj_title, key_name)
|
|
|
|
|
|
|
|
required = key_name in required_keys
|
|
|
|
|
|
|
|
res = process_prop(key_name, props[key_name], required,
|
|
|
|
|
|
|
|
mark_required)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
first_table_rows.append(res["row"])
|
|
|
|
|
|
|
|
tables.extend(res["tables"])
|
|
|
|
|
|
|
|
logger.debug("Done property %s" % key_name)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
except Exception, e:
|
|
|
|
|
|
|
|
e2 = Exception("Error reading property %s.%s: %s" %
|
|
|
|
|
|
|
|
(obj_title, key_name, str(e)))
|
|
|
|
|
|
|
|
# throw the new exception with the old stack trace, so that
|
|
|
|
|
|
|
|
# we don't lose information about where the error occurred.
|
|
|
|
|
|
|
|
raise e2, None, sys.exc_info()[2]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tables.insert(0, {
|
|
|
|
|
|
|
|
"title": obj_title,
|
|
|
|
|
|
|
|
"rows": first_table_rows,
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return tables
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def process_prop(key_name, prop, required, mark_required):
|
|
|
|
|
|
|
|
prop = inherit_parents(prop)
|
|
|
|
|
|
|
|
|
|
|
|
value_type = None
|
|
|
|
value_type = None
|
|
|
|
required = key_name in required_keys
|
|
|
|
|
|
|
|
desc = prop.get("description", "")
|
|
|
|
desc = prop.get("description", "")
|
|
|
|
prop_type = prop.get('type')
|
|
|
|
prop_type = prop.get('type')
|
|
|
|
|
|
|
|
tables = []
|
|
|
|
|
|
|
|
|
|
|
|
if prop_type is None:
|
|
|
|
if prop_type is None:
|
|
|
|
raise KeyError("Property '%s' of object '%s' missing 'type' field"
|
|
|
|
raise KeyError("Property '%s' of object '%s' missing 'type' field"
|
|
|
@ -233,18 +255,20 @@ def get_json_schema_object_fields(obj, enforce_title=False,
|
|
|
|
if isinstance(value_type, list):
|
|
|
|
if isinstance(value_type, list):
|
|
|
|
value_type = " or ".join(value_type)
|
|
|
|
value_type = " or ".join(value_type)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if required and mark_required:
|
|
|
|
if required and mark_required:
|
|
|
|
desc = "**Required.** " + desc
|
|
|
|
desc = "**Required.** " + desc
|
|
|
|
fields["rows"].append({
|
|
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
|
|
|
"row": {
|
|
|
|
"key": key_name,
|
|
|
|
"key": key_name,
|
|
|
|
"type": value_type,
|
|
|
|
"type": value_type,
|
|
|
|
"id": value_id,
|
|
|
|
"id": value_id,
|
|
|
|
"required": required,
|
|
|
|
"required": required,
|
|
|
|
"desc": desc,
|
|
|
|
"desc": desc,
|
|
|
|
})
|
|
|
|
},
|
|
|
|
logger.debug("Done property %s" % key_name)
|
|
|
|
"tables": tables,
|
|
|
|
|
|
|
|
}
|
|
|
|
return tables
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_tables_for_schema(schema, mark_required=True):
|
|
|
|
def get_tables_for_schema(schema, mark_required=True):
|
|
|
@ -611,9 +635,23 @@ class MatrixUnits(Units):
|
|
|
|
if not filename.startswith("m."):
|
|
|
|
if not filename.startswith("m."):
|
|
|
|
continue
|
|
|
|
continue
|
|
|
|
filepath = os.path.join(path, filename)
|
|
|
|
filepath = os.path.join(path, filename)
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
schemata[filename] = self.read_event_schema(filepath)
|
|
|
|
|
|
|
|
except Exception, e:
|
|
|
|
|
|
|
|
e2 = Exception("Error reading event schema "+filepath+": "+
|
|
|
|
|
|
|
|
str(e))
|
|
|
|
|
|
|
|
# throw the new exception with the old stack trace, so that
|
|
|
|
|
|
|
|
# we don't lose information about where the error occurred.
|
|
|
|
|
|
|
|
raise e2, None, sys.exc_info()[2]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return schemata
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def read_event_schema(self, filepath):
|
|
|
|
self.log("Reading %s" % filepath)
|
|
|
|
self.log("Reading %s" % filepath)
|
|
|
|
|
|
|
|
|
|
|
|
with open(filepath, "r") as f:
|
|
|
|
with open(filepath, "r") as f:
|
|
|
|
json_schema = yaml.load(f)
|
|
|
|
json_schema = yaml.load(f)
|
|
|
|
|
|
|
|
|
|
|
|
schema = {
|
|
|
|
schema = {
|
|
|
|
"typeof": None,
|
|
|
|
"typeof": None,
|
|
|
|
"typeof_info": "",
|
|
|
|
"typeof_info": "",
|
|
|
@ -692,8 +730,7 @@ class MatrixUnits(Units):
|
|
|
|
raise Exception("Missing description for state_key")
|
|
|
|
raise Exception("Missing description for state_key")
|
|
|
|
schema["typeof_info"] = "``state_key``: %s" % skey_desc
|
|
|
|
schema["typeof_info"] = "``state_key``: %s" % skey_desc
|
|
|
|
|
|
|
|
|
|
|
|
schemata[filename] = schema
|
|
|
|
return schema
|
|
|
|
return schemata
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def load_changelogs(self):
|
|
|
|
def load_changelogs(self):
|
|
|
|
changelogs = {}
|
|
|
|
changelogs = {}
|
|
|
|